-
Notifications
You must be signed in to change notification settings - Fork 149
perf(l1)!: change jump_targets to a bitmap #5739
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3075841
change jump target to a bitmap
edg-l e4cb60d
update version
edg-l c4e208c
Merge branch 'main' into perf_bitmap_jumps
edg-l bab8cec
changelog
edg-l 2508cf0
Merge branch 'main' into perf_bitmap_jumps
edg-l 7e3c65b
Merge branch 'main' into perf_bitmap_jumps
edg-l File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,11 +29,12 @@ pub struct Code { | |
| // endpoints to access that hash, saving one expensive Keccak hash. | ||
| pub hash: H256, | ||
| pub bytecode: Bytes, | ||
| // TODO: Consider using Arc<[u32]> (needs to enable serde rc feature) | ||
| // TODO: Consider using Arc<[u64]> (needs to enable serde rc feature) | ||
| // The valid addresses are 32-bit because, despite EIP-3860 restricting initcode size, | ||
| // this does not apply to previous forks. This is tested in the EEST tests, which would | ||
| // panic in debug mode. | ||
| pub jump_targets: Vec<u32>, | ||
| // Bitmap of valid JUMPDEST destinations. | ||
| pub jump_targets: Vec<u64>, | ||
| } | ||
|
|
||
| impl Code { | ||
|
|
@@ -58,16 +59,18 @@ impl Code { | |
| } | ||
| } | ||
|
|
||
| fn compute_jump_targets(code: &[u8]) -> Vec<u32> { | ||
| fn compute_jump_targets(code: &[u8]) -> Vec<u64> { | ||
| debug_assert!(code.len() <= u32::MAX as usize); | ||
| let mut targets = Vec::new(); | ||
| let mut bitmap = vec![0u64; code.len().div_ceil(64)]; | ||
| let mut i = 0; | ||
| while i < code.len() { | ||
| // TODO: we don't use the constants from the vm module to avoid a circular dependency | ||
| match code[i] { | ||
| // OP_JUMPDEST | ||
| 0x5B => { | ||
| targets.push(i as u32); | ||
| let word = i / 64; | ||
| let bit = i % 64; | ||
| bitmap[word] |= 1u64 << bit; | ||
| } | ||
| // OP_PUSH1..32 | ||
| c @ 0x60..0x80 => { | ||
|
|
@@ -78,7 +81,7 @@ impl Code { | |
| } | ||
| i += 1; | ||
| } | ||
| targets | ||
| bitmap | ||
| } | ||
|
|
||
| /// Estimates the size of the Code struct in bytes | ||
|
|
@@ -92,8 +95,8 @@ impl Code { | |
| pub fn size(&self) -> usize { | ||
| let hash_size = size_of::<H256>(); | ||
| let bytes_size = size_of::<Bytes>(); | ||
| let vec_size = size_of::<Vec<u32>>() + self.jump_targets.len() * size_of::<u32>(); | ||
| hash_size + bytes_size + vec_size | ||
| let bitmap_size = size_of::<Vec<u64>>() + self.jump_targets.len() * size_of::<u64>(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use |
||
| hash_size + bytes_size + bitmap_size | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This comment should be updated, since it's about the specifics of the old implementation