Skip to content

Commit c799853

Browse files
authored
perf: use fxhash for coverage hitmap (#11155)
1 parent 0d5c6fa commit c799853

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

crates/evm/coverage/src/inspector.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl LineCoverageCollector {
7272
#[cold]
7373
#[inline(never)]
7474
fn insert_map(&mut self, interpreter: &mut Interpreter) {
75-
let hash = interpreter.bytecode.hash().unwrap_or_else(|| eof_panic());
75+
let hash = interpreter.bytecode.hash().unwrap();
7676
self.current_hash = hash;
7777
// Converts the mutable reference to a `NonNull` pointer.
7878
self.current_map = self
@@ -89,14 +89,10 @@ impl LineCoverageCollector {
8989
/// tx) then the hash is calculated from the bytecode.
9090
#[inline]
9191
fn get_or_insert_contract_hash(interpreter: &mut Interpreter) -> B256 {
92-
if interpreter.bytecode.hash().is_none_or(|h| h.is_zero()) {
93-
interpreter.bytecode.regenerate_hash();
94-
}
95-
interpreter.bytecode.hash().unwrap_or_else(|| eof_panic())
96-
}
97-
98-
#[cold]
99-
#[inline(never)]
100-
fn eof_panic() -> ! {
101-
panic!("coverage does not support EOF");
92+
// TODO: use just `get_or_calculate_hash`
93+
interpreter
94+
.bytecode
95+
.hash()
96+
.filter(|h| !h.is_zero())
97+
.unwrap_or_else(|| interpreter.bytecode.regenerate_hash())
10298
}

crates/evm/coverage/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern crate tracing;
1010

1111
use alloy_primitives::{
1212
Bytes,
13-
map::{B256HashMap, HashMap},
13+
map::{B256HashMap, HashMap, rustc_hash::FxHashMap},
1414
};
1515
use analysis::SourceAnalysis;
1616
use eyre::Result;
@@ -208,8 +208,8 @@ impl DerefMut for HitMaps {
208208
/// Contains low-level data about hit counters for the instructions in the bytecode of a contract.
209209
#[derive(Clone, Debug)]
210210
pub struct HitMap {
211+
hits: FxHashMap<u32, u32>,
211212
bytecode: Bytes,
212-
hits: HashMap<u32, u32>,
213213
}
214214

215215
impl HitMap {

0 commit comments

Comments
 (0)