Skip to content

Commit 190f90e

Browse files
authored
Never inline the prepare functions (bluealloy#712)
These functions are used for keeping the stack memory clean on the host recursive code paths. EVM supports up to 1024 levels of recursion, so if one is not careful with the stack memory allocations, the stack memory can blow up. Benchmarks show dramatic stack memory improvements when ont inlining these functions. A recursive bomb uses around 1.1MB of stack when these functions are not inlined. If inlined the recursive bombs blow up the stack.
1 parent 26dc07d commit 190f90e

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

bins/revme/src/statetest/runner.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,7 @@ pub fn run(
365365
let console_bar = console_bar.clone();
366366
let elapsed = elapsed.clone();
367367

368-
let mut thread = std::thread::Builder::new();
369-
370-
// Allow bigger stack in debug mode to prevent stack overflow errors
371-
//if cfg!(debug_assertions) {
372-
thread = thread.stack_size(4 * 1024 * 1024);
373-
//}
368+
let thread: std::thread::Builder = std::thread::Builder::new();
374369

375370
joins.push(
376371
thread

crates/interpreter/src/instructions/host.rs

+2
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ pub fn selfdestruct<SPEC: Spec>(interpreter: &mut Interpreter, host: &mut dyn Ho
239239
interpreter.instruction_result = InstructionResult::SelfDestruct;
240240
}
241241

242+
#[inline(never)]
242243
pub fn prepare_create_inputs<const IS_CREATE2: bool, SPEC: Spec>(
243244
interpreter: &mut Interpreter,
244245
host: &mut dyn Host,
@@ -368,6 +369,7 @@ pub fn static_call<SPEC: Spec>(interpreter: &mut Interpreter, host: &mut dyn Hos
368369
call_inner::<SPEC>(interpreter, CallScheme::StaticCall, host);
369370
}
370371

372+
#[inline(never)]
371373
fn prepare_call_inputs<SPEC: Spec>(
372374
interpreter: &mut Interpreter,
373375
scheme: CallScheme,

crates/revm/src/evm_impl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
340340
(new_state, logs, gas_used, gas_refunded)
341341
}
342342

343+
#[inline(never)]
343344
fn prepare_create(&mut self, inputs: &CreateInputs) -> Result<PreparedCreate, CreateResult> {
344345
let gas = Gas::new(inputs.gas_limit);
345346

@@ -629,6 +630,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
629630
}
630631
}
631632

633+
#[inline(never)]
632634
fn prepare_call(&mut self, inputs: &CallInputs) -> Result<PreparedCall, CallResult> {
633635
let gas = Gas::new(inputs.gas_limit);
634636
let account = match self

0 commit comments

Comments
 (0)