Skip to content

Commit

Permalink
perf: make read origin a small vec
Browse files Browse the repository at this point in the history
  • Loading branch information
hai-rise committed Aug 20, 2024
1 parent acd7cab commit d9d3bb7
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bitvec = "1.0.1"
dashmap = "6.0.1"
defer-drop = "1.3.0"
serde = "1.0.204"
smallvec = "1.13.2"

# Let's do our best to port needed REVM changes upstream
revm = { git = "https://github.com/risechain/revm", rev = "7b42abb672deacde9e0538e8e74209e1943dabff", features = [
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::collections::HashMap;
use std::hash::{BuildHasherDefault, Hasher};

use alloy_primitives::{Address, B256, U256};
use smallvec::SmallVec;

// We take the last 8 bytes of an address as its hash. This
// seems fine as the addresses themselves are hash suffixes,
Expand Down Expand Up @@ -151,7 +152,7 @@ enum ReadOrigin {

// For validation: a list of read origins (previous transaction versions)
// for each read memory location.
type ReadSet = HashMap<MemoryLocationHash, Vec<ReadOrigin>, BuildIdentityHasher>;
type ReadSet = HashMap<MemoryLocationHash, SmallVec<[ReadOrigin; 1]>, BuildIdentityHasher>;

// The updates made by this transaction incarnation, which is applied
// to the multi-version data structure at the end of execution.
Expand Down
3 changes: 2 additions & 1 deletion src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use revm::{
},
Context, Database, Evm, EvmContext,
};
use smallvec::SmallVec;
use std::collections::HashMap;

use crate::{
Expand Down Expand Up @@ -238,7 +239,7 @@ impl<'a, S: Storage, C: PevmChain> Database for VmDb<'a, S, C> {
// We accumulate new origins to either:
// - match with the previous origins to check consistency
// - register origins on the first read
let mut new_origins = Vec::new();
let mut new_origins = SmallVec::new();

let mut final_account = None;
let mut balance_addition = U256::ZERO;
Expand Down

0 comments on commit d9d3bb7

Please sign in to comment.