-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: Add parallel state root computation support for Bonsai trie #9576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
app/src/main/java/org/hyperledger/besu/cli/options/storage/PathBasedExtraStorageOptions.java
Outdated
Show resolved
Hide resolved
app/src/test/java/org/hyperledger/besu/cli/options/stable/DataStorageOptionsTest.java
Show resolved
Hide resolved
.../main/java/org/hyperledger/besu/ethereum/trie/patricia/ParallelStoredMerklePatriciaTrie.java
Outdated
Show resolved
Hide resolved
| this.root = loadNode(root); | ||
|
|
||
| // Convert pending updates to UpdateEntry objects with nibble paths | ||
| final List<UpdateEntry<V>> entries = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to use simple for loops to avoid steams overhead on memory allocations and latency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check this branch that has the change that replaces streams with simple for loops.
| for (final Map.Entry<Byte, List<UpdateEntry<V>>> entry : largeGroups.entrySet()) { | ||
| final byte nibble = entry.getKey(); | ||
| final List<UpdateEntry<V>> childUpdates = entry.getValue(); | ||
| final Bytes childLocation = Bytes.concatenate(location, Bytes.of(nibble)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| final Bytes childLocation = Bytes.concatenate(location, Bytes.of(nibble)); | |
| final byte[] out = new byte[pathDepth + 1]; | |
| final byte[] in = location.toArrayUnsafe(); | |
| System.arraycopy(in, 0, out, 0, pathDepth); | |
| out[len] = nibble; | |
| final Bytes childLocation = Bytes.wrap(out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This the JMH benchmark that shows the different in performance. arraycopy_newArray_wrap is the new suggested implementation
Benchmark (locationSize) Mode Cnt Score Error Units
BytesConcatenateBenchmark.arraycopy_newArray_wrap 8 avgt 16 6.313 ± 0.321 ns/op
BytesConcatenateBenchmark.arraycopy_newArray_wrap 16 avgt 16 6.150 ± 0.140 ns/op
BytesConcatenateBenchmark.arraycopy_newArray_wrap 32 avgt 16 6.383 ± 0.291 ns/op
BytesConcatenateBenchmark.concat_bytesOf 8 avgt 16 37.773 ± 6.029 ns/op
BytesConcatenateBenchmark.concat_bytesOf 16 avgt 16 35.169 ± 2.331 ns/op
BytesConcatenateBenchmark.concat_bytesOf 32 avgt 16 36.688 ± 1.568 ns/op
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check this branch with a clean implementation
| for (final Map.Entry<Byte, List<UpdateEntry<V>>> entry : smallGroups.entrySet()) { | ||
| final byte nibble = entry.getKey(); | ||
| final List<UpdateEntry<V>> childUpdates = entry.getValue(); | ||
| final Bytes childLocation = Bytes.concatenate(location, Bytes.of(nibble)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same as above, create a method that concatenates based on the underlying array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposed changes can be addressed in a separate PR as this PR is about state root calculation.
For the instance type (8 Cores / 8 threads) we used in the screenshot below, it shows up to 40% improvement in block processing time. We've seeing less improvement on VMs with less cores (4 cores / 8 threads).

Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
PR description
Description
This PR introduces parallel processing capabilities for Merkle Patricia Trie operations during state root computation in Bonsai storage format, significantly improving block validation performance.
Changes
Core Implementation
ParallelStoredMerklePatriciaTrie: New parallel implementation ofStoredMerklePatriciaTrieForkJoinPoolConfiguration
WorldStateConfig: AddedisParallelStateRootComputationEnabledflag (default:true)PathBasedExtraStorageConfiguration: Added parallel state root computation configuration--bonsai-parallel-state-root-computation-enabledto enable/disable featureKey Features
Backward Compatibility
StoredMerklePatriciaTriewhen disabledConfiguration Examples