From 8bbba049491500bd6622b9683ec10e4527a8495b Mon Sep 17 00:00:00 2001 From: ivan-aksamentov Date: Fri, 6 Dec 2024 00:46:45 +0100 Subject: [PATCH 1/2] perf: set jemalloc as global allocator --- Cargo.lock | 21 +++++++++++++++++++++ Cargo.toml | 1 + packages/treetime/Cargo.toml | 1 + packages/treetime/src/lib.rs | 5 +++++ 4 files changed, 28 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index d696c9c7..9a5b6417 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3761,6 +3761,26 @@ dependencies = [ "weezl", ] +[[package]] +name = "tikv-jemalloc-sys" +version = "0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd3c60906412afa9c2b5b5a48ca6a5abe5736aec9eb48ad05037a677e52e4e2d" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "tikv-jemallocator" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cec5ff18518d81584f477e9bfdf957f5bb0979b0bac3af4ca30b5b3ae2d2865" +dependencies = [ + "libc", + "tikv-jemalloc-sys", +] + [[package]] name = "time" version = "0.3.36" @@ -3963,6 +3983,7 @@ dependencies = [ "strum", "strum_macros", "textplots", + "tikv-jemallocator", "time", "traversal", "usher-mat-utils", diff --git a/Cargo.toml b/Cargo.toml index aa7db36f..edc00bc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -123,6 +123,7 @@ statrs = "=0.17.1" strum = "=0.26.3" strum_macros = "=0.26.4" textplots = "=0.8.6" +tikv-jemallocator = "=0.6.0" time = { version = "=0.3.36", features = ["serde", "macros", "parsing"] } traversal = "=0.1.2" typify = { version = "=0.2.0", features = ["macro"] } diff --git a/packages/treetime/Cargo.toml b/packages/treetime/Cargo.toml index c6a6f813..a03d2799 100644 --- a/packages/treetime/Cargo.toml +++ b/packages/treetime/Cargo.toml @@ -79,6 +79,7 @@ serde_yaml = { workspace = true } smart-default = { workspace = true } strum = { workspace = true } strum_macros = { workspace = true } +tikv-jemallocator = { workspace = true } time = { workspace = true } traversal = { workspace = true } diff --git a/packages/treetime/src/lib.rs b/packages/treetime/src/lib.rs index bb67cc43..6d3ac98f 100644 --- a/packages/treetime/src/lib.rs +++ b/packages/treetime/src/lib.rs @@ -10,6 +10,11 @@ pub mod representation; pub mod seq; pub mod utils; +use tikv_jemallocator::Jemalloc; + +#[global_allocator] +static GLOBAL: Jemalloc = Jemalloc; + #[cfg(test)] mod tests { use crate::utils::global_init::global_init; From 1acf00b17d929152a8164933d57f2cf5288810c5 Mon Sep 17 00:00:00 2001 From: ivan-aksamentov Date: Fri, 6 Dec 2024 02:43:02 +0100 Subject: [PATCH 2/2] fix: only enable jemalloc on supported platforms It does not even build on darwin or mingw --- packages/treetime/Cargo.toml | 15 ++++++++++++++- packages/treetime/src/lib.rs | 10 +++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/treetime/Cargo.toml b/packages/treetime/Cargo.toml index a03d2799..3a977e99 100644 --- a/packages/treetime/Cargo.toml +++ b/packages/treetime/Cargo.toml @@ -79,10 +79,23 @@ serde_yaml = { workspace = true } smart-default = { workspace = true } strum = { workspace = true } strum_macros = { workspace = true } -tikv-jemallocator = { workspace = true } +tikv-jemallocator = { workspace = true, optional = true } time = { workspace = true } traversal = { workspace = true } +[target.'cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))'.dependencies] +tikv-jemallocator = { workspace = true } + +[target.'cfg(all(target_arch = "aarch64", target_os = "linux", target_env = "gnu"))'.dependencies] +tikv-jemallocator = { workspace = true } + +[target.'cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "musl"))'.dependencies] +tikv-jemallocator = { workspace = true } + +[target.'cfg(all(target_arch = "aarch64", target_os = "linux", target_env = "musl"))'.dependencies] +tikv-jemallocator = { workspace = true } + + [features] "png" = ["image", "plotters/bitmap_backend", "plotters/ttf"] diff --git a/packages/treetime/src/lib.rs b/packages/treetime/src/lib.rs index 6d3ac98f..20df0f0e 100644 --- a/packages/treetime/src/lib.rs +++ b/packages/treetime/src/lib.rs @@ -10,10 +10,14 @@ pub mod representation; pub mod seq; pub mod utils; -use tikv_jemallocator::Jemalloc; - +#[cfg(any( + all(target_arch = "aarch64", target_os = "linux", target_env = "gnu"), + all(target_arch = "aarch64", target_os = "linux", target_env = "musl"), + all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"), + all(target_arch = "x86_64", target_os = "linux", target_env = "musl"), +))] #[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; #[cfg(test)] mod tests {