fix: improve performance of ApplyPowerTableDiffs in ImportSnapshotToDatastore#1047
Merged
Kubuxu merged 4 commits intofilecoin-project:mainfrom Aug 13, 2025
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1047 +/- ##
==========================================
- Coverage 64.77% 64.46% -0.31%
==========================================
Files 81 81
Lines 9896 9942 +46
==========================================
- Hits 6410 6409 -1
- Misses 2961 2999 +38
- Partials 525 534 +9
🚀 New features to boost your workflow:
|
5fbd9b1 to
af0db51
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes the performance of applying power table diffs during F3 snapshot import by introducing a new map-based approach that avoids expensive sorting operations on each iteration. The optimization shows a ~99% performance improvement when importing mainnet F3 snapshots.
- Introduced
ApplyPowerTableDiffsToMapfunction to work with power table maps instead of sorted arrays - Added comprehensive validation for instance numbers, latest instance bounds, and power table CID verification
- Refactored
importSnapshotToDatastoreWithTestingPowerTableFrequencyto use the new map-based approach and include additional safety checks
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| certstore/snapshot.go | Refactored snapshot import logic to use map-based power table operations and added validation checks |
| certs/certs.go | Added new map-based power table diff functions and helper functions for array-map conversion |
Contributor
|
SGTM apart from the two issues highlighted by Copilot |
Kubuxu
approved these changes
Aug 13, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
sortoperation inApplyPowerTableDiffsturns out to be expensive.This PR introduces another
func ApplyPowerTableDiffsToMap(powerTableMap map[gpbft.ActorID]gpbft.PowerEntry, diffs ...PowerTableDiff) (map[gpbft.ActorID]gpbft.PowerEntry, error)to avoid sorting.It also adds more validations against first instance, latest instance and powertable cid.
Perf stats of importing a mainnet F3 snapshot on my laptop show ~99% perf gain