From 3140bd863d6bb812add53b87fa20a94302582d3c Mon Sep 17 00:00:00 2001 From: Wataxi Date: Thu, 30 Apr 2026 02:09:25 +0800 Subject: [PATCH] perf(engine): use Entry API in `insert_executed` Replace `contains_key` + `insert` in `TreeState::insert_executed` with a single `entry()` match, dropping the duplicate hash lookup on every block insertion. Matches the pattern already used in `remove_by_hash` and `block_buffer::insert_block`. --- crates/engine/tree/src/tree/state.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/engine/tree/src/tree/state.rs b/crates/engine/tree/src/tree/state.rs index a5b3e40d0b0..313a7b127e2 100644 --- a/crates/engine/tree/src/tree/state.rs +++ b/crates/engine/tree/src/tree/state.rs @@ -165,12 +165,13 @@ impl TreeState { let parent_hash = executed.recovered_block().parent_hash(); let block_number = executed.recovered_block().number(); - if self.blocks_by_hash.contains_key(&hash) { - return; + match self.blocks_by_hash.entry(hash) { + hash_map::Entry::Occupied(_) => return, + hash_map::Entry::Vacant(entry) => { + entry.insert(executed.clone()); + } } - self.blocks_by_hash.insert(hash, executed.clone()); - self.blocks_by_number.entry(block_number).or_default().push(executed); self.parent_to_child.entry(parent_hash).or_default().insert(hash);