Skip to content

Commit 33d7aa2

Browse files
committed
perf: inline step and step_end dispatchers
1 parent 29d231c commit 33d7aa2

File tree

1 file changed

+48
-28
lines changed

1 file changed

+48
-28
lines changed

crates/evm/evm/src/inspectors/stack.rs

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -299,19 +299,21 @@ pub struct InspectorStack {
299299
/// See [`InspectorStack`].
300300
#[derive(Default, Clone, Debug)]
301301
pub struct InspectorStackInner {
302+
// Inspectors.
302303
pub chisel_state: Option<ChiselState>,
303-
pub line_coverage: Option<LineCoverageCollector>,
304304
pub edge_coverage: Option<EdgeCovInspector>,
305305
pub fuzzer: Option<Fuzzer>,
306+
pub line_coverage: Option<LineCoverageCollector>,
306307
pub log_collector: Option<LogCollector>,
307308
pub printer: Option<CustomPrintTracer>,
308-
pub tracer: Option<TracingInspector>,
309+
pub revert_diag: Option<RevertDiagnostic>,
309310
pub script_execution_inspector: Option<ScriptExecutionInspector>,
311+
pub tracer: Option<TracingInspector>,
312+
313+
// InspectorExt and other internal data.
310314
pub enable_isolation: bool,
311315
pub odyssey: bool,
312316
pub create2_deployer: Address,
313-
pub revert_diag: Option<RevertDiagnostic>,
314-
315317
/// Flag marking if we are in the inner EVM context.
316318
pub in_inner_context: bool,
317319
pub inner_context_data: Option<InnerContextData>,
@@ -788,63 +790,83 @@ impl InspectorStackRefMut<'_> {
788790
ecx.journaled_state.state = std::mem::take(&mut self.top_frame_journal);
789791
}
790792
}
791-
}
792793

793-
impl Inspector<EthEvmContext<&mut dyn DatabaseExt>> for InspectorStackRefMut<'_> {
794-
fn initialize_interp(
794+
#[inline(always)]
795+
fn step_inlined(
795796
&mut self,
796797
interpreter: &mut Interpreter,
797798
ecx: &mut EthEvmContext<&mut dyn DatabaseExt>,
798799
) {
799800
call_inspectors!(
800801
[
801-
&mut self.line_coverage,
802+
&mut self.fuzzer,
802803
&mut self.tracer,
803-
&mut self.cheatcodes,
804+
&mut self.line_coverage,
805+
&mut self.edge_coverage,
804806
&mut self.script_execution_inspector,
805-
&mut self.printer
807+
&mut self.printer,
808+
&mut self.revert_diag,
809+
// Keep `cheatcodes` last to make use of the tail call.
810+
&mut self.cheatcodes,
806811
],
807-
|inspector| inspector.initialize_interp(interpreter, ecx),
812+
|inspector| (*inspector).step(interpreter, ecx),
808813
);
809814
}
810815

811-
fn step(
816+
#[inline(always)]
817+
fn step_end_inlined(
812818
&mut self,
813819
interpreter: &mut Interpreter,
814820
ecx: &mut EthEvmContext<&mut dyn DatabaseExt>,
815821
) {
816822
call_inspectors!(
817823
[
818-
&mut self.fuzzer,
819824
&mut self.tracer,
820-
&mut self.line_coverage,
821-
&mut self.edge_coverage,
822-
&mut self.cheatcodes,
823-
&mut self.script_execution_inspector,
825+
&mut self.chisel_state,
824826
&mut self.printer,
825-
&mut self.revert_diag
827+
&mut self.revert_diag,
828+
// Keep `cheatcodes` last to make use of the tail call.
829+
&mut self.cheatcodes,
826830
],
827-
|inspector| inspector.step(interpreter, ecx),
831+
|inspector| (*inspector).step_end(interpreter, ecx),
828832
);
829833
}
834+
}
830835

831-
fn step_end(
836+
impl Inspector<EthEvmContext<&mut dyn DatabaseExt>> for InspectorStackRefMut<'_> {
837+
fn initialize_interp(
832838
&mut self,
833839
interpreter: &mut Interpreter,
834840
ecx: &mut EthEvmContext<&mut dyn DatabaseExt>,
835841
) {
836842
call_inspectors!(
837843
[
844+
&mut self.line_coverage,
838845
&mut self.tracer,
839846
&mut self.cheatcodes,
840-
&mut self.chisel_state,
841-
&mut self.printer,
842-
&mut self.revert_diag
847+
&mut self.script_execution_inspector,
848+
&mut self.printer
843849
],
844-
|inspector| inspector.step_end(interpreter, ecx),
850+
|inspector| inspector.initialize_interp(interpreter, ecx),
845851
);
846852
}
847853

854+
fn step(
855+
&mut self,
856+
interpreter: &mut Interpreter,
857+
ecx: &mut EthEvmContext<&mut dyn DatabaseExt>,
858+
) {
859+
self.step_inlined(interpreter, ecx);
860+
}
861+
862+
fn step_end(
863+
&mut self,
864+
interpreter: &mut Interpreter,
865+
ecx: &mut EthEvmContext<&mut dyn DatabaseExt>,
866+
) {
867+
self.step_end_inlined(interpreter, ecx);
868+
}
869+
848870
#[allow(clippy::redundant_clone)]
849871
fn log(
850872
&mut self,
@@ -1063,22 +1085,20 @@ impl InspectorExt for InspectorStackRefMut<'_> {
10631085
}
10641086

10651087
impl Inspector<EthEvmContext<&mut dyn DatabaseExt>> for InspectorStack {
1066-
#[inline]
10671088
fn step(
10681089
&mut self,
10691090
interpreter: &mut Interpreter,
10701091
ecx: &mut EthEvmContext<&mut dyn DatabaseExt>,
10711092
) {
1072-
self.as_mut().step(interpreter, ecx)
1093+
self.as_mut().step_inlined(interpreter, ecx)
10731094
}
10741095

1075-
#[inline]
10761096
fn step_end(
10771097
&mut self,
10781098
interpreter: &mut Interpreter,
10791099
ecx: &mut EthEvmContext<&mut dyn DatabaseExt>,
10801100
) {
1081-
self.as_mut().step_end(interpreter, ecx)
1101+
self.as_mut().step_end_inlined(interpreter, ecx)
10821102
}
10831103

10841104
fn call(

0 commit comments

Comments
 (0)