mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-19 03:04:27 -05:00
feat(trie): ParallelSparseTrie: Compute lower subtrie hashes in parallel (#17173)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -10611,6 +10611,7 @@ dependencies = [
|
||||
"proptest-arbitrary-interop",
|
||||
"rand 0.8.5",
|
||||
"rand 0.9.1",
|
||||
"rayon",
|
||||
"reth-execution-errors",
|
||||
"reth-primitives-traits",
|
||||
"reth-trie",
|
||||
|
||||
@@ -25,6 +25,7 @@ alloy-rlp.workspace = true
|
||||
|
||||
# misc
|
||||
smallvec.workspace = true
|
||||
rayon = { workspace = true, optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
# reth
|
||||
@@ -33,6 +34,7 @@ reth-trie-common = { workspace = true, features = ["test-utils", "arbitrary"] }
|
||||
reth-trie.workspace = true
|
||||
reth-trie-sparse = { workspace = true, features = ["test-utils"] }
|
||||
|
||||
# misc
|
||||
arbitrary.workspace = true
|
||||
assert_matches.workspace = true
|
||||
itertools.workspace = true
|
||||
@@ -40,3 +42,17 @@ proptest-arbitrary-interop.workspace = true
|
||||
proptest.workspace = true
|
||||
rand.workspace = true
|
||||
rand_08.workspace = true
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"dep:rayon",
|
||||
"alloy-primitives/std",
|
||||
"alloy-rlp/std",
|
||||
"alloy-trie/std",
|
||||
"reth-execution-errors/std",
|
||||
"reth-primitives-traits/std",
|
||||
"reth-trie-common/std",
|
||||
"reth-trie-sparse/std",
|
||||
"tracing/std",
|
||||
]
|
||||
|
||||
@@ -769,13 +769,28 @@ impl ParallelSparseTrie {
|
||||
// Update the prefix set with the keys that didn't have matching subtries
|
||||
self.prefix_set = unchanged_prefix_set;
|
||||
|
||||
// Update subtrie hashes in parallel
|
||||
// TODO: call `update_hashes` on each subtrie in parallel
|
||||
let (tx, rx) = mpsc::channel();
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
// Update subtrie hashes serially if nostd
|
||||
for ChangedSubtrie { index, mut subtrie, mut prefix_set } in subtries {
|
||||
subtrie.update_hashes(&mut prefix_set);
|
||||
tx.send((index, subtrie)).unwrap();
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
// Update subtrie hashes in parallel
|
||||
{
|
||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||
subtries
|
||||
.into_par_iter()
|
||||
.map(|ChangedSubtrie { index, mut subtrie, mut prefix_set }| {
|
||||
subtrie.update_hashes(&mut prefix_set);
|
||||
(index, subtrie)
|
||||
})
|
||||
.for_each_init(|| tx.clone(), |tx, result| tx.send(result).unwrap());
|
||||
}
|
||||
|
||||
drop(tx);
|
||||
|
||||
// Return updated subtries back to the trie
|
||||
|
||||
Reference in New Issue
Block a user