Skip to content

Commit d4a7898

Browse files
authored
perf: lazy cheatcodes SignaturesIdentifier, save only if online (#11708)
1 parent 74254b9 commit d4a7898

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

crates/cheatcodes/src/inspector.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use std::{
7272
io::BufReader,
7373
ops::Range,
7474
path::PathBuf,
75-
sync::Arc,
75+
sync::{Arc, OnceLock},
7676
};
7777

7878
mod utils;
@@ -498,7 +498,7 @@ pub struct Cheatcodes {
498498
/// Unlocked wallets used in scripts and testing of scripts.
499499
pub wallets: Option<Wallets>,
500500
/// Signatures identifier for decoding events and functions
501-
pub signatures_identifier: Option<SignaturesIdentifier>,
501+
signatures_identifier: OnceLock<Option<SignaturesIdentifier>>,
502502
/// Used to determine whether the broadcasted call has non-fixed gas limit.
503503
/// Holds values for (seen opcode GAS, seen opcode CALL) pair.
504504
/// If GAS opcode is followed by CALL opcode then both flags are marked true and call
@@ -558,7 +558,7 @@ impl Cheatcodes {
558558
arbitrary_storage: Default::default(),
559559
deprecated: Default::default(),
560560
wallets: Default::default(),
561-
signatures_identifier: SignaturesIdentifier::new(true).ok(),
561+
signatures_identifier: Default::default(),
562562
dynamic_gas_limit_sequence: Default::default(),
563563
}
564564
}
@@ -585,6 +585,11 @@ impl Cheatcodes {
585585
self.active_delegations.push(authorization);
586586
}
587587

588+
/// Returns the signatures identifier.
589+
pub fn signatures_identifier(&self) -> Option<&SignaturesIdentifier> {
590+
self.signatures_identifier.get_or_init(|| SignaturesIdentifier::new(true).ok()).as_ref()
591+
}
592+
588593
/// Decodes the input data and applies the cheatcode.
589594
fn apply_cheatcode(
590595
&mut self,

crates/cheatcodes/src/test/expect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ pub(crate) fn handle_expect_emit(
898898

899899
// Try to decode the events if we have a signature identifier
900900
let (expected_decoded, actual_decoded) = if let Some(signatures_identifier) =
901-
&state.signatures_identifier
901+
state.signatures_identifier()
902902
&& !event_to_fill_or_check.anonymous
903903
{
904904
(

crates/evm/traces/src/identifier/signatures.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ impl SignaturesIdentifier {
274274

275275
impl SignaturesIdentifierInner {
276276
fn save(&self) {
277-
if let Some(path) = &self.cache_path {
277+
// We only identify new signatures if the client is enabled.
278+
if let Some(path) = &self.cache_path
279+
&& self.client.is_some()
280+
{
278281
self.cache
279282
.try_read()
280283
.expect("SignaturesIdentifier cache is locked while attempting to save")

0 commit comments

Comments
 (0)