commitment: eliminate BranchMerger from fold→encode→write hot path#20548
Open
commitment: eliminate BranchMerger from fold→encode→write hot path#20548
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the commitment trie “fold → encode → write” path by always encoding complete BranchData (all afterMap cells), eliminating the need to merge partial branch encodings with previous data.
Changes:
- Update
foldBranch()to encode withbitmap = afterMapand to passtouchMap=afterMapso writtenBranchDatais complete. - Remove
BranchMergerusage from both immediate (CollectUpdate) and deferred (encodeDeferredUpdate/ApplyDeferredBranchUpdates) encoding paths, including removing the merger pool and encoder field. - Add benchmarks to compare encode-direct vs the prior encode+merge approach, and add a completed implementation plan doc.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| execution/commitment/hex_patricia_hashed.go | Switch branch encoding bitmap to afterMap and pass complete maps into update collection. |
| execution/commitment/commitment.go | Remove merger from encoder/deferred update hot paths and simplify worker pooling accordingly. |
| execution/commitment/commitment_bench_test.go | Add benchmarks for EncodeBranch and end-to-end encode+merge vs encode-direct comparison. |
| docs/plans/completed/20260413-complete-branchdata-encoding.md | Document the approach, testing strategy, and benchmark expectations/results for the change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Encode complete BranchData (full afterMap) instead of partial data that required a merge step on the read path. Changes: - foldBranch(): use afterMap as the encoding bitmap instead of touchMap & afterMap — encoded branch now contains all cells - CollectUpdate(): remove merger.Merge(prev, update) call; remove merger field and pool from BranchEncoder - encodeDeferredUpdate(): remove merger parameter and workerMergerPool; update all callers in ApplyDeferredBranchUpdates - Add benchmarks: BenchmarkEncodeBranch, BenchmarkCollectUpdate_EncodeDirect Benchmark results (encode+merge vs encode-direct): 2 cells: ~174 ns/op → ~118 ns/op (-32%) 8 cells: ~454 ns/op → ~404 ns/op (-11%) 16 cells: ~868 ns/op → ~813 ns/op (-6%)
a8ec16d to
59eee40
Compare
Member
Author
|
branch works multiple steps but even wit revert of f5593e6 still have gas mismatch on it after a while |
Member
Author
|
Collaborator
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.
Summary
Encode complete
BranchData(fullafterMap) instead of partial data that required aMergestep on the read path. This removesBranchMergerentirely from the hot path.Changes
foldBranch(): useafterMapas the encoding bitmap instead oftouchMap & afterMap— encoded branch now contains all cellsCollectUpdate()(immediate path): removemerger.Merge(prev, update)call; removemergerfield and pool fromBranchEncoderencodeDeferredUpdate()(deferred path): removemergerparameter andworkerMergerPool; update all callers inApplyDeferredBranchUpdatesBenchmarkEncodeBranch,BenchmarkCollectUpdate_EncodeDirectBenchmark Results (encode+merge vs encode-direct)
Verification
make lintpassesmake erigon integrationbuilds successfully