Skip to content

Commit 4aa13e2

Browse files
committed
perf: tweak optimizations again
1 parent 52ecd5c commit 4aa13e2

File tree

6 files changed

+35
-25
lines changed

6 files changed

+35
-25
lines changed

Cargo.toml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,22 @@ debug = 0
1919

2020
# Speed up tests and dev build
2121
[profile.dev.package]
22+
# solc
23+
ethers-solc.opt-level = 3
24+
solang-parser.opt-level = 3
25+
serde_json.opt-level = 3
26+
2227
# evm
2328
revm.opt-level = 3
2429
revm-primitives.opt-level = 3
2530
revm-interpreter.opt-level = 3
2631
revm-precompile.opt-level = 3
2732
tiny-keccak.opt-level = 3
33+
sha2.opt-level = 3
34+
sha3.opt-level = 3
35+
keccak.opt-level = 3
2836
ruint.opt-level = 3
29-
primitive-types.opt-level = 3
37+
hashbrown.opt-level = 3
3038

3139
# keystores
3240
scrypt.opt-level = 3
@@ -48,7 +56,6 @@ codegen-units = 1
4856
# Package overrides
4957
foundry-evm.opt-level = 3
5058

51-
ethers-solc.opt-level = 1
5259
foundry-abi.opt-level = 1
5360
mdbook.opt-level = 1
5461
protobuf.opt-level = 1
@@ -93,12 +100,11 @@ wasm-bindgen-backend.opt-level = 0
93100

94101
# Local "release" mode, more optimized than dev but much faster to compile than release
95102
[profile.local]
96-
inherits = "release"
103+
inherits = "dev"
97104
opt-level = 1
98-
lto = "none"
105+
strip = true
106+
panic = "abort"
99107
codegen-units = 16
100-
# Empty, clears `profile.release.package`
101-
package = {}
102108

103109
[workspace.dependencies]
104110
anvil = { path = "crates/anvil" }

crates/cli/src/utils/cmd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,15 +393,15 @@ pub async fn handle_traces(
393393
let (sources, bytecode) = etherscan_identifier.get_compiled_contracts().await?;
394394
run_debugger(result, decoder, bytecode, sources)?;
395395
} else {
396-
print_traces(&mut result, decoder, verbose).await?;
396+
print_traces(&mut result, &decoder, verbose).await?;
397397
}
398398

399399
Ok(())
400400
}
401401

402402
pub async fn print_traces(
403403
result: &mut TraceResult,
404-
decoder: CallTraceDecoder,
404+
decoder: &CallTraceDecoder,
405405
verbose: bool,
406406
) -> Result<()> {
407407
if result.traces.is_empty() {

crates/evm/src/fuzz/invariant/error.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,12 @@ impl InvariantFuzzError {
166166
anchor: usize,
167167
removed_calls: &[usize],
168168
) -> Result<Vec<&'a BasicTxDetails>, ()> {
169-
let calls = calls.iter().enumerate().filter_map(|(index, element)| {
169+
let mut new_sequence = Vec::with_capacity(calls.len());
170+
for (index, details) in calls.iter().enumerate() {
170171
if anchor > index || removed_calls.contains(&index) {
171-
return None
172+
continue
172173
}
173-
Some(element)
174-
});
175174

176-
let mut new_sequence = vec![];
177-
for details in calls {
178175
new_sequence.push(details);
179176

180177
let (sender, (addr, bytes)) = details;

crates/evm/src/fuzz/invariant/executor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ impl<'a> InvariantExecutor<'a> {
9898
/// Returns a list of all the consumed gas and calldata of every invariant fuzz case
9999
pub fn invariant_fuzz(
100100
&mut self,
101-
invariant_contract: InvariantContract,
101+
invariant_contract: &InvariantContract,
102102
) -> eyre::Result<InvariantFuzzTestResult> {
103-
let (fuzz_state, targeted_contracts, strat) = self.prepare_fuzzing(&invariant_contract)?;
103+
let (fuzz_state, targeted_contracts, strat) = self.prepare_fuzzing(invariant_contract)?;
104104

105105
// Stores the consumed gas and calldata of every successful fuzz call.
106106
let fuzz_cases: RefCell<Vec<FuzzedCases>> = RefCell::new(Default::default());
@@ -113,7 +113,7 @@ impl<'a> InvariantExecutor<'a> {
113113

114114
let last_call_results = RefCell::new(
115115
assert_invariants(
116-
&invariant_contract,
116+
invariant_contract,
117117
&blank_executor.borrow(),
118118
&[],
119119
&mut failures.borrow_mut(),
@@ -199,7 +199,7 @@ impl<'a> InvariantExecutor<'a> {
199199
});
200200

201201
let RichInvariantResults { success: can_continue, call_results } = can_continue(
202-
&invariant_contract,
202+
invariant_contract,
203203
call_result,
204204
&executor,
205205
&inputs,

crates/evm/src/trace/decoder.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use ethers::{
1515
};
1616
use foundry_common::{abi::get_indexed_event, SELECTOR_LEN};
1717
use hashbrown::HashSet;
18+
use once_cell::sync::OnceCell;
1819
use std::collections::{BTreeMap, HashMap};
1920

2021
/// Build a new [CallTraceDecoder].
@@ -25,7 +26,7 @@ pub struct CallTraceDecoderBuilder {
2526

2627
impl CallTraceDecoderBuilder {
2728
pub fn new() -> Self {
28-
Self { decoder: CallTraceDecoder::new() }
29+
Self { decoder: CallTraceDecoder::new().clone() }
2930
}
3031

3132
/// Add known labels to the decoder.
@@ -65,7 +66,7 @@ impl CallTraceDecoderBuilder {
6566
///
6667
/// Note that a call trace decoder is required for each new set of traces, since addresses in
6768
/// different sets might overlap.
68-
#[derive(Default, Debug)]
69+
#[derive(Clone, Default, Debug)]
6970
pub struct CallTraceDecoder {
7071
/// Information for decoding precompile calls.
7172
pub precompiles: HashMap<Address, Function>,
@@ -115,7 +116,14 @@ impl CallTraceDecoder {
115116
///
116117
/// The call trace decoder always knows how to decode calls to the cheatcode address, as well
117118
/// as DSTest-style logs.
118-
pub fn new() -> Self {
119+
pub fn new() -> &'static Self {
120+
// If you want to take arguments in this function, assign them to the fields of the cloned
121+
// lazy instead of removing it
122+
static INIT: OnceCell<CallTraceDecoder> = OnceCell::new();
123+
INIT.get_or_init(Self::init)
124+
}
125+
126+
fn init() -> Self {
119127
Self {
120128
// TODO: These are the Ethereum precompiles. We should add a way to support precompiles
121129
// for other networks, too.

crates/forge/src/runner.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,15 +451,14 @@ impl<'a> ContractRunner<'a> {
451451
InvariantContract { address, invariant_functions: functions, abi: self.contract };
452452

453453
let Ok(InvariantFuzzTestResult { invariants, cases, reverts, last_run_inputs }) =
454-
evm.invariant_fuzz(invariant_contract.clone())
454+
evm.invariant_fuzz(&invariant_contract)
455455
else {
456456
return vec![]
457457
};
458458

459459
invariants
460460
.into_values()
461-
.map(|test_error| {
462-
let (test_error, invariant) = test_error;
461+
.map(|(test_error, invariant)| {
463462
let mut counterexample = None;
464463
let mut logs = logs.clone();
465464
let mut traces = traces.clone();
@@ -495,7 +494,7 @@ impl<'a> ContractRunner<'a> {
495494
// If invariants ran successfully, replay the last run to collect logs and
496495
// traces.
497496
replay_run(
498-
&invariant_contract.clone(),
497+
&invariant_contract,
499498
self.executor.clone(),
500499
known_contracts,
501500
identified_contracts.clone(),

0 commit comments

Comments
 (0)