-
Notifications
You must be signed in to change notification settings - Fork 130
perf(levm): use bitmap for jumpdests #4608
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
Conversation
Lines of code reportTotal lines added: Detailed view |
Benchmark Results ComparisonNo significant difference was registered for any benchmark run. Detailed ResultsBenchmark Results: BubbleSort
Benchmark Results: ERC20Approval
Benchmark Results: ERC20Mint
Benchmark Results: ERC20Transfer
Benchmark Results: Factorial
Benchmark Results: FactorialRecursive
Benchmark Results: Fibonacci
Benchmark Results: FibonacciRecursive
Benchmark Results: ManyHashes
Benchmark Results: MstoreBench
Benchmark Results: Push
Benchmark Results: SstoreBench_no_opt
|
Benchmark Block Execution Results Comparison Against Main
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes the JumpTargetFilter implementation to address a performance bottleneck where the original is_blacklisted function consumed ~30% of execution time during mainnet block execution.
- Replaces incremental iteration with precomputed bitmap approach using
BitVec<u8, Msb0> - Changes
is_blacklistedfrom potentially O(n) to O(1) lookup operation - Adopts Geth's
codeBitmapstrategy for identifying validJUMPDESTpositions
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/vm/levm/src/utils.rs | Refactors JumpTargetFilter to use bitmap-based jumpdest tracking instead of incremental filtering |
| crates/vm/levm/Cargo.toml | Adds bitvec dependency for bitmap functionality |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…ex into jump_dest_filter_opt
JereSalo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just check if it's a jumpdest rather than checking that it's not blacklisted now that we have a bitvec with jumpdests? It feels more straightforward and less complex but I don't know if the other approach has more benefits
Co-authored-by: Copilot <[email protected]>
| None => { | ||
| let code = &self.bytecode; | ||
| let len = code.len(); | ||
| let mut jumpdests = bitvec![u8, Msb0; 0; len]; // All false, size = len |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could try using the default usize instead of u8 here, as the documentation states:
If you are only using this crate to discard the seven wasted bits per bool in a collection of bools, and are not too concerned about the in-memory representation, then you should use the default type argument of usize. This is because most processors work best when moving an entire usize between memory and the processor itself, and using a smaller type may cause it to slow down. Additionally, processor instructions are typically optimized for the whole register, and the processor might need to do additional clearing work for narrower types.
Also, Lsb0 might be a better default here, according to the docs:
The default ordering is Lsb0, as it typically produces shorter object code than Msb0 does.

Motivation
The original
is_blacklistedfunction inJumpTargetFilterwas a performance bottleneck, consuming ~30% of execution time during mainnet blocks stateless execution.Description
Inspired by Geth's
codeBitmapapproach, this PR:BitVec<u8, Lsb0>where bits mark validJUMPDESTpositions, skippingPUSH1..PUSH32data bytes.is_blacklistedto O(1) bit lookup:address >= bytecode.len() || !jumpdests[address].Performance Results
Execution Times
Average speedup: 1.083x
Proving Times
Average speedup: 1.123x
Higher-gas blocks (e.g., 23619126) show the most gains, improving scalability for zkVM workloads.