Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Evm structure (Cached Instructions and Precompiles) #2049

Merged
merged 17 commits into from
Feb 7, 2025

Conversation

rakita
Copy link
Member

@rakita rakita commented Feb 4, 2025

Closing #2017 and #2018

To address performance degradation that happens on initializing the instruction table and easier use for the inspector, new struct Evm is made to contain Context, Inspector, Instructions and Precompiles.

pub struct Evm<CTX, INSP, I, P> {
    pub data: EvmData<CTX, INSP>,
    pub enabled_inspection: bool,
    pub instruction: I,
    pub precompiles: P,
}

pub struct EvmData<CTX, INSP> {
    pub ctx: CTX,
    pub inspector: INSP,
}

An additional step for building Evm is added, so usage is now:

let ctx = Context::mainnet()
    .with_db(BenchmarkDB::new_bytecode(bytecode.clone()))
    .modify_tx_chained(|tx| {
        tx.caller = BENCH_CALLER;
        tx.kind = TxKind::Call(BENCH_TARGET);
        tx.gas_limit = 21100;
    });

// new step that builds instructions and precompiles.
let mut evm = ctx.build_mainnet_with_inspector(StackInspector::default());

// Run evm.
evm.inspect_previous().unwrap();

Inspector logic is now a trait similar to EthHandler EthInspectorHandler that is easy to apply to new structures.
Context getters are aggregated into one ContextTrait(Name pending) trait.

Still WIP

Copy link

codspeed-hq bot commented Feb 4, 2025

CodSpeed Performance Report

Merging #2049 will improve performances by 48.11%

Comparing rakita/evm_structure (fff44da) with main (83a3087)

Summary

⚡ 2 improvements
✅ 6 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
analysis 263.9 µs 220 µs +19.99%
transfer 132.9 µs 89.7 µs +48.11%

@rakita rakita marked this pull request as ready for review February 7, 2025 02:38
@rakita rakita merged commit b3fbb88 into main Feb 7, 2025
28 checks passed
@github-actions github-actions bot mentioned this pull request Feb 7, 2025
@rakita rakita deleted the rakita/evm_structure branch February 7, 2025 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant