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 jemalloc as the global allocator on unix (try 2) #7448

Merged
merged 1 commit into from
Mar 28, 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
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ jobs:
target="${{ matrix.target }}"
flags=()
# `keccak-asm` does not support MSVC or aarch64 Linux.
[[ "$target" != *msvc* && "$target" != "aarch64-unknown-linux-gnu" ]] && flags+=(--features=asm-keccak)
# `jemalloc` and `keccak-asm` are not supported on MSVC or aarch64 Linux.
if [[ "$target" != *msvc* && "$target" != "aarch64-unknown-linux-gnu" ]]; then
flags+=(--features asm-keccak,jemalloc)
fi
[[ "$target" == *windows* ]] && exe=".exe"
Expand Down
24 changes: 24 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ ruint.opt-level = 3
sha2.opt-level = 3
sha3.opt-level = 3
tiny-keccak.opt-level = 3
bitvec.opt-level = 3

# fuzzing
proptest.opt-level = 3
Expand Down Expand Up @@ -208,6 +209,7 @@ tracing = "0.1"
tracing-subscriber = "0.3"
vergen = { version = "8", default-features = false }
indexmap = "2.2"
tikv-jemallocator = "0.5.4"

axum = "0.6"
hyper = "0.14"
Expand Down
18 changes: 8 additions & 10 deletions crates/anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ path = "src/anvil.rs"
required-features = ["cli"]

[build-dependencies]
vergen = { workspace = true, default-features = false, features = [
"build",
"git",
"gitcl",
] }
vergen = { workspace = true, default-features = false, features = ["build", "git", "gitcl"] }

[dependencies]
# foundry internal
Expand Down Expand Up @@ -81,11 +77,7 @@ rand = "0.8"
eyre.workspace = true

# cli
clap = { version = "4", features = [
"derive",
"env",
"wrap_help",
], optional = true }
clap = { version = "4", features = ["derive", "env", "wrap_help"], optional = true }
clap_complete = { version = "4", optional = true }
chrono.workspace = true
auto_impl = "1"
Expand All @@ -94,6 +86,9 @@ fdlimit = { version = "0.3", optional = true }
clap_complete_fig = "4"
ethereum-forkid = "0.12"

[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { workspace = true, optional = true }

[dev-dependencies]
alloy-json-abi.workspace = true
ethers = { workspace = true, features = ["abigen"] }
Expand All @@ -109,3 +104,6 @@ default = ["cli"]
cmd = ["clap", "clap_complete", "ctrlc", "anvil-server/clap"]
cli = ["tokio/full", "cmd", "fdlimit"]
asm-keccak = ["alloy-primitives/asm-keccak"]
# TODO: parity dependencies are not compatible with a different global allocator.
# jemalloc = ["dep:tikv-jemallocator"]
jemalloc = []
6 changes: 6 additions & 0 deletions crates/anvil/src/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ use anvil::cmd::NodeArgs;
use clap::{CommandFactory, Parser, Subcommand};
use foundry_cli::utils;

// TODO: parity dependencies are not compatible with a different global allocator.
#[cfg(any())]
#[cfg(all(feature = "jemalloc", unix))]
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

/// A fast local Ethereum development node.
#[derive(Parser)]
#[command(name = "anvil", version = anvil::VERSION_MESSAGE, next_display_order = None)]
Expand Down
4 changes: 4 additions & 0 deletions crates/cast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ tracing.workspace = true
yansi = "0.5"
evmole = "0.3.1"

[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { workspace = true, optional = true }

[dev-dependencies]
foundry-test-utils.workspace = true
async-trait = "0.1"
Expand All @@ -85,6 +88,7 @@ default = ["rustls"]
rustls = ["foundry-cli/rustls", "foundry-wallets/rustls"]
openssl = ["foundry-cli/openssl", "foundry-wallets/openssl"]
asm-keccak = ["alloy-primitives/asm-keccak"]
jemalloc = ["dep:tikv-jemallocator"]

[[bench]]
name = "vanity"
Expand Down
4 changes: 4 additions & 0 deletions crates/cast/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ pub mod tx;

use opts::{Cast as Opts, CastSubcommand, ToBaseArgs};

#[cfg(all(feature = "jemalloc", unix))]
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

#[tokio::main]
async fn main() -> Result<()> {
handler::install();
Expand Down
4 changes: 4 additions & 0 deletions crates/chisel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ tokio = { version = "1", features = ["full"] }
yansi = "0.5"
tracing.workspace = true

[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { workspace = true, optional = true }

[dev-dependencies]
criterion = { version = "0.5", features = ["async_tokio"] }
once_cell = "1"
Expand All @@ -61,6 +64,7 @@ default = ["rustls"]
rustls = ["reqwest/rustls-tls", "reqwest/rustls-tls-native-roots"]
openssl = ["foundry-compilers/openssl", "reqwest/default-tls"]
asm-keccak = ["alloy-primitives/asm-keccak"]
jemalloc = ["dep:tikv-jemallocator"]

[[bench]]
name = "session_source"
Expand Down
4 changes: 4 additions & 0 deletions crates/chisel/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ use std::path::PathBuf;
use tracing::debug;
use yansi::Paint;

#[cfg(all(feature = "jemalloc", unix))]
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

// Loads project's figment and merges the build cli arguments into it
foundry_config::merge_impl_figment_convert!(Chisel, opts, evm_opts);

Expand Down
4 changes: 4 additions & 0 deletions crates/forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ hyper.workspace = true
tower-http = { workspace = true, features = ["fs"] }
opener = "0.6"

[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { workspace = true, optional = true }

[dev-dependencies]
anvil.workspace = true
foundry-test-utils.workspace = true
Expand All @@ -110,6 +113,7 @@ rustls = [
]
openssl = ["foundry-cli/openssl", "reqwest/default-tls", "foundry-wallets/openssl"]
asm-keccak = ["alloy-primitives/asm-keccak"]
jemalloc = ["dep:tikv-jemallocator"]

[[bench]]
name = "test"
Expand Down
8 changes: 6 additions & 2 deletions crates/forge/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ use eyre::Result;
use foundry_cli::{handler, utils};

mod cmd;
mod opts;

use cmd::{cache::CacheSubcommands, generate::GenerateSubcommands, watch};

mod opts;
use opts::{Forge, ForgeSubcommand};

#[cfg(all(feature = "jemalloc", unix))]
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

fn main() -> Result<()> {
handler::install();
utils::load_dotenv();
Expand Down
Loading