From f74e5942922746beb0f07f8ede53b29748ab25d6 Mon Sep 17 00:00:00 2001 From: Huber Date: Mon, 2 Feb 2026 11:31:47 +0200 Subject: [PATCH] perf(trie): dispatch V2 storage proofs in lexicographical order (#21684) --- crates/trie/parallel/src/proof_task.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/trie/parallel/src/proof_task.rs b/crates/trie/parallel/src/proof_task.rs index a5914f1e66..078baa4ef0 100644 --- a/crates/trie/parallel/src/proof_task.rs +++ b/crates/trie/parallel/src/proof_task.rs @@ -1828,8 +1828,14 @@ fn dispatch_v2_storage_proofs( } } + // Sort storage targets by address for optimal dispatch order. + // Since trie walk processes accounts in lexicographical order, dispatching in the same order + // reduces head-of-line blocking when consuming results. + let mut sorted_storage_targets: Vec<_> = storage_targets.into_iter().collect(); + sorted_storage_targets.sort_unstable_by_key(|(addr, _)| *addr); + // Dispatch all proofs for targeted storage slots - for (hashed_address, targets) in storage_targets { + for (hashed_address, targets) in sorted_storage_targets { // Create channel for receiving StorageProofResultMessage let (result_tx, result_rx) = crossbeam_channel::unbounded(); let input = StorageProofInput::new(hashed_address, targets);