From bc57f720425c44cf21082ff6657d7f47dbc01a19 Mon Sep 17 00:00:00 2001 From: Jeff Bencin Date: Sun, 11 Feb 2024 16:24:49 -0500 Subject: [PATCH] chore: Use `jemalloc` global allocator on supported platforms --- Cargo.lock | 22 ++++++++++++++++++++++ Cargo.toml | 1 + stackslib/Cargo.toml | 3 +++ stackslib/src/main.rs | 7 +++++++ testnet/stacks-node/Cargo.toml | 3 +++ testnet/stacks-node/src/main.rs | 7 +++++++ 6 files changed, 43 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 41c2c8e924f..18da327b74c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3393,6 +3393,7 @@ dependencies = [ "stacks-signer", "stackslib", "stx-genesis", + "tikv-jemallocator", "tokio", "toml", "tracing", @@ -3474,6 +3475,7 @@ dependencies = [ "stacks-common", "stdext", "stx-genesis", + "tikv-jemallocator", "time 0.2.27", "url", "winapi 0.3.9", @@ -3691,6 +3693,26 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tikv-jemalloc-sys" +version = "0.5.4+5.3.0-patched" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9402443cb8fd499b6f327e40565234ff34dbda27460c5b47db0db77443dd85d1" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "tikv-jemallocator" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "965fe0c26be5c56c94e38ba547249074803efd52adfb66de62107d95aab3eaca" +dependencies = [ + "libc", + "tikv-jemalloc-sys", +] + [[package]] name = "time" version = "0.1.45" diff --git a/Cargo.toml b/Cargo.toml index 265dc3cee5a..102276218b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ members = [ wsts = { version = "8.0", default-features = false } rand_core = "0.6" rand = "0.8" +tikv-jemallocator = "0.5.4" # Use a bit more than default optimization for # dev builds to speed up test execution diff --git a/stackslib/Cargo.toml b/stackslib/Cargo.toml index c5411353e21..c0344b2d977 100644 --- a/stackslib/Cargo.toml +++ b/stackslib/Cargo.toml @@ -59,6 +59,9 @@ wsts = {workspace = true} rand_core = {workspace = true} hashbrown = "0.14" +[target.'cfg(not(target_env = "msvc"))'.dependencies] +tikv-jemallocator = {workspace = true} + [target.'cfg(unix)'.dependencies] nix = "0.23" diff --git a/stackslib/src/main.rs b/stackslib/src/main.rs index ff5413fb145..1bc6a5ccc23 100644 --- a/stackslib/src/main.rs +++ b/stackslib/src/main.rs @@ -26,6 +26,13 @@ extern crate stacks_common; #[macro_use(o, slog_log, slog_trace, slog_debug, slog_info, slog_warn, slog_error)] extern crate slog; +#[cfg(not(target_env = "msvc"))] +use tikv_jemallocator::Jemalloc; + +#[cfg(not(target_env = "msvc"))] +#[global_allocator] +static GLOBAL: Jemalloc = Jemalloc; + use std::collections::{HashMap, HashSet}; use std::convert::TryFrom; use std::fs::{File, OpenOptions}; diff --git a/testnet/stacks-node/Cargo.toml b/testnet/stacks-node/Cargo.toml index ae53315a7fa..b5b1f2870b4 100644 --- a/testnet/stacks-node/Cargo.toml +++ b/testnet/stacks-node/Cargo.toml @@ -32,6 +32,9 @@ rand = { workspace = true } rand_core = { workspace = true } hashbrown = "0.14" +[target.'cfg(not(target_env = "msvc"))'.dependencies] +tikv-jemallocator = {workspace = true} + [dev-dependencies] ring = "0.16.19" warp = "0.3.5" diff --git a/testnet/stacks-node/src/main.rs b/testnet/stacks-node/src/main.rs index 3418ed97269..08da97dd538 100644 --- a/testnet/stacks-node/src/main.rs +++ b/testnet/stacks-node/src/main.rs @@ -58,6 +58,13 @@ use crate::mockamoto::MockamotoNode; use crate::neon_node::{BlockMinerThread, TipCandidate}; use crate::run_loop::boot_nakamoto; +#[cfg(not(target_env = "msvc"))] +use tikv_jemallocator::Jemalloc; + +#[cfg(not(target_env = "msvc"))] +#[global_allocator] +static GLOBAL: Jemalloc = Jemalloc; + /// Implmentation of `pick_best_tip` CLI option fn cli_pick_best_tip(config_path: &str, at_stacks_height: Option) -> TipCandidate { info!("Loading config at path {}", config_path);