perf: small performance and safety improvements#2868
Merged
Conversation
- Remove unwrap() in primitives::short_address by using direct array indexing - Use lazy allocation with or_insert_with to avoid unnecessary Vec allocations - Pre-allocate Vec capacity in State::increment_balances based on iterator hint - Simplify iterator pattern in bundle_state to use destructuring - Use mem::take instead of mem::replace for bool values - Add #[inline] attributes to small hot-path functions in state module - Use unwrap_or_default() instead of unwrap_or(0) for cleaner code These are small incremental improvements that enhance performance and code safety without changing functionality.
kevaundray
reviewed
Aug 8, 2025
| pub fn short_address(address: &Address) -> Option<usize> { | ||
| if address.0[..18].iter().all(|b| *b == 0) { | ||
| let short_address = u16::from_be_bytes(address.0[18..].try_into().unwrap()) as usize; | ||
| let short_address = u16::from_be_bytes([address.0[18], address.0[19]]) as usize; |
Contributor
There was a problem hiding this comment.
Noting: an address is 20 bytes, so this is equivalent.
Hopefully the compiler can figure it out and avoid the bounds checks
Member
Author
There was a problem hiding this comment.
It is a constant index to an array that is of fixed size, compiler has all the information needed to optimise it
CodSpeed Performance ReportMerging #2868 will not alter performanceComparing Summary
|
lwedge99
pushed a commit
to sentioxyz/revm
that referenced
this pull request
Sep 16, 2025
- Remove unwrap() in primitives::short_address by using direct array indexing - Use lazy allocation with or_insert_with to avoid unnecessary Vec allocations - Pre-allocate Vec capacity in State::increment_balances based on iterator hint - Simplify iterator pattern in bundle_state to use destructuring - Use mem::take instead of mem::replace for bool values - Add #[inline] attributes to small hot-path functions in state module - Use unwrap_or_default() instead of unwrap_or(0) for cleaner code These are small incremental improvements that enhance performance and code safety without changing functionality.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
These are small incremental improvements that enhance performance and code safety without changing functionality.