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

perf: use hashbrown for HashMap and HashSet #476

Merged
merged 8 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on: [pull_request]
name: bench
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
runBenchmark:
name: run benchmark
runs-on: buildjet-16vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v3
- uses: boa-dev/criterion-compare-action@v3
with:
package: "heimdall-core"
branchName: ${{ github.base_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions crates/cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ repository.workspace = true
keywords.workspace = true
exclude.workspace = true

[lib]
bench = false

[dependencies]
clap = { workspace = true, features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
Expand Down
3 changes: 3 additions & 0 deletions crates/cfg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ repository.workspace = true
keywords.workspace = true
exclude.workspace = true

[lib]
bench = false

[dependencies]
heimdall-config = { workspace = true }
heimdall-common = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ homepage.workspace = true
repository.workspace = true
keywords.workspace = true
exclude.workspace = true
bench = false

[dependencies]
clap = { workspace = true, features = ["derive"] }
Expand All @@ -32,3 +33,4 @@ async-trait = "0.1.51"
[[bin]]
name = "heimdall"
path = "src/main.rs"
bench = false
5 changes: 5 additions & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ homepage.workspace = true
repository.workspace = true
keywords.workspace = true
exclude.workspace = true
bench = false

[lib]
bench = false

[dependencies]
async-openai = "0.10.0"
Expand Down Expand Up @@ -38,3 +42,4 @@ alloy = { version = "0.1.3", features = ["full", "rpc-types-debug", "rpc-types-t
bytes = "1.6.1"
alloy-dyn-abi = "0.7.7"
tokio-retry = "0.3.0"
hashbrown = "0.14.5"
4 changes: 4 additions & 0 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ homepage.workspace = true
repository.workspace = true
keywords.workspace = true
exclude.workspace = true
bench = false

[lib]
bench = false

[dependencies]
heimdall-common = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ repository.workspace = true
keywords.workspace = true
exclude.workspace = true

[lib]
bench = false

[dependencies]
async-recursion = "1.0.5"
thiserror = "1.0.50"
Expand Down
5 changes: 5 additions & 0 deletions crates/decode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ homepage.workspace = true
repository.workspace = true
keywords.workspace = true
exclude.workspace = true
bench = false

[lib]
bench = false

[dependencies]
heimdall-config = { workspace = true }
Expand All @@ -24,3 +28,4 @@ alloy-dyn-abi = "0.7.7"
alloy-json-abi = "0.7.6"
alloy = { version = "0.1.3", features = ["full", "rpc-types-debug", "rpc-types-trace"] }
serde_json = "1.0"
hashbrown = "0.14.5"
3 changes: 2 additions & 1 deletion crates/decode/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{collections::HashSet, time::Instant};
use hashbrown::HashSet;
use std::time::Instant;

use alloy::primitives::Selector;
use alloy_dyn_abi::{DynSolCall, DynSolReturns, DynSolType};
Expand Down
2 changes: 1 addition & 1 deletion crates/decode/src/utils/abi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashSet;
use hashbrown::HashSet;

use alloy::primitives::{Selector, U256};
use alloy_dyn_abi::{DynSolCall, DynSolReturns, DynSolType, DynSolValue};
Expand Down
5 changes: 5 additions & 0 deletions crates/decompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ homepage.workspace = true
repository.workspace = true
keywords.workspace = true
exclude.workspace = true
bench = false

[lib]
bench = false

[dependencies]
heimdall-config = { workspace = true }
Expand All @@ -28,6 +32,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
alloy-dyn-abi = "0.7.7"
alloy = { version = "0.1.3", features = ["full", "rpc-types-debug", "rpc-types-trace"] }
hashbrown = "0.14.5"

heimdall-disassembler.workspace = true
heimdall-vm.workspace = true
6 changes: 2 additions & 4 deletions crates/decompile/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use alloy::primitives::Address;
use alloy_dyn_abi::{DynSolType, DynSolValue};
use alloy_json_abi::JsonAbi;
use eyre::eyre;
use hashbrown::HashMap;
use heimdall_common::{
ether::{
compiler::detect_compiler,
Expand All @@ -20,10 +21,7 @@ use heimdall_vm::{
core::vm::VM,
ext::selectors::{find_function_selectors, resolve_selectors},
};
use std::{
collections::HashMap,
time::{Duration, Instant},
};
use std::time::{Duration, Instant};

use crate::{
core::{
Expand Down
3 changes: 2 additions & 1 deletion crates/decompile/src/core/out/abi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{collections::HashMap, time::Instant};
use hashbrown::HashMap;
use std::time::Instant;

use alloy_json_abi::{Error, Event, EventParam, Function, JsonAbi, Param, StateMutability};

Expand Down
6 changes: 2 additions & 4 deletions crates/decompile/src/core/out/source.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::{
collections::{HashMap, HashSet},
time::Instant,
};
use hashbrown::{HashMap, HashSet};
use std::time::Instant;

use alloy_json_abi::StateMutability;

Expand Down
3 changes: 2 additions & 1 deletion crates/decompile/src/core/postprocess.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{collections::HashMap, time::Instant};
use hashbrown::HashMap;
use std::time::Instant;

use eyre::eyre;
use heimdall_common::utils::strings::find_balanced_encapsulator;
Expand Down
2 changes: 1 addition & 1 deletion crates/decompile/src/interfaces/function.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet};
use hashbrown::{HashMap, HashSet};

use alloy::primitives::U256;
use heimdall_common::ether::signatures::ResolvedFunction;
Expand Down
2 changes: 1 addition & 1 deletion crates/decompile/src/utils/heuristics/arguments.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashSet;
use hashbrown::HashSet;

use alloy::primitives::U256;
use eyre::eyre;
Expand Down
4 changes: 4 additions & 0 deletions crates/disassemble/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ homepage.workspace = true
repository.workspace = true
keywords.workspace = true
exclude.workspace = true
bench = false

[lib]
bench = false

[dependencies]
heimdall-config = { workspace = true }
Expand Down
5 changes: 5 additions & 0 deletions crates/dump/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ homepage.workspace = true
repository.workspace = true
keywords.workspace = true
exclude.workspace = true
bench = false

[lib]
bench = false

[dependencies]
heimdall-config = { workspace = true }
Expand All @@ -22,3 +26,4 @@ eyre = "0.6.12"
tokio = { version = "1", features = ["full"] }
futures = "0.3.30"
alloy = { version = "0.1.3", features = ["full", "rpc-types-debug", "rpc-types-trace"] }
hashbrown = "0.14.5"
4 changes: 3 additions & 1 deletion crates/dump/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ use alloy::{
};
use eyre::eyre;
use futures::future::try_join_all;
use hashbrown::HashMap;
use heimdall_common::{
ether::rpc::{get_block_state_diff, latest_block_number},
utils::time::{calculate_eta, format_eta},
};
use std::{collections::HashMap, sync::Arc, time::Instant};

use std::{sync::Arc, time::Instant};
use tokio::sync::{Mutex, Semaphore};
use tracing::{debug, info};

Expand Down
5 changes: 5 additions & 0 deletions crates/inspect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ homepage.workspace = true
repository.workspace = true
keywords.workspace = true
exclude.workspace = true
bench = false

[lib]
bench = false

[dependencies]
heimdall-config = { workspace = true }
Expand All @@ -27,3 +31,4 @@ async-recursion = "1.0.5"
tokio = { version = "1", features = ["full"] }
alloy = { version = "0.1.3", features = ["full", "rpc-types-debug", "rpc-types-trace"] }
serde_json = "1.0"
hashbrown = "0.14.5"
2 changes: 1 addition & 1 deletion crates/inspect/src/interfaces/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet};
use hashbrown::{HashMap, HashSet};

use alloy::primitives::Address;
use futures::future::try_join_all;
Expand Down
6 changes: 2 additions & 4 deletions crates/inspect/src/interfaces/traces.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::{
borrow::BorrowMut,
collections::{HashSet, VecDeque},
};
use hashbrown::HashSet;
use std::{borrow::BorrowMut, collections::VecDeque};

use alloy::{
dyn_abi::DynSolValue,
Expand Down
4 changes: 4 additions & 0 deletions crates/tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ homepage.workspace = true
repository.workspace = true
keywords.workspace = true
exclude.workspace = true
bench = false

[lib]
bench = false

[dependencies]
clap = { workspace = true, features = ["derive"] }
Expand Down
5 changes: 5 additions & 0 deletions crates/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ homepage.workspace = true
repository.workspace = true
keywords.workspace = true
exclude.workspace = true
bench = false

[lib]
bench = false

[dependencies]
async-openai = "0.10.0"
Expand All @@ -34,6 +38,7 @@ tracing = "0.1.40"
eyre = "0.6.12"
heimdall-common.workspace = true
alloy = { version = "0.1.3", features = ["full", "rpc-types-debug", "rpc-types-trace"] }
hashbrown = "0.14.5"

[features]
step-tracing = []
Expand Down
7 changes: 3 additions & 4 deletions crates/vm/src/core/stack.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::{
collections::VecDeque,
fmt::Display,
hash::{Hash, Hasher},
hash::{BuildHasher, Hash},
};

use alloy::primitives::U256;
use eyre::{OptionExt, Result};
use hashbrown::hash_map::DefaultHashBuilder;

use super::opcodes::WrappedOpcode;

Expand Down Expand Up @@ -258,9 +259,7 @@ impl Stack {
/// assert_eq!(stack.hash(), 0x00);
/// ```
pub fn hash(&self) -> u64 {
let mut hasher = std::collections::hash_map::DefaultHasher::new();
self.stack.hash(&mut hasher);
hasher.finish()
DefaultHashBuilder::default().hash_one(&self.stack)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/core/storage.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet};
use hashbrown::{HashMap, HashSet};

use alloy::primitives::U256;

Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/core/vm.rs
Jon-Becker marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use hashbrown::HashSet;
use std::{
collections::HashSet,
ops::{Div, Rem, Shl, Shr},
time::{SystemTime, UNIX_EPOCH},
};
Expand Down
3 changes: 2 additions & 1 deletion crates/vm/src/ext/exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ use crate::{
},
};
use eyre::{OptionExt, Result};
use hashbrown::HashMap;
use heimdall_common::utils::strings::decode_hex;
use std::{collections::HashMap, time::Instant};
use std::time::Instant;
use tracing::{trace, warn};

#[derive(Clone, Debug, Default)]
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/ext/exec/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use hashbrown::HashMap;

use alloy::primitives::U256;
use heimdall_common::constants::{MEMORY_REGEX, STORAGE_REGEX};
Expand Down
Loading
Loading