diff --git a/Cargo.lock b/Cargo.lock index 697b024..cebb40b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2223,6 +2223,16 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "libmimalloc-sys" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23aa6811d3bd4deb8a84dde645f943476d13b248d818edcf8ce0b2f37f036b44" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "libredox" version = "0.0.2" @@ -2339,6 +2349,15 @@ dependencies = [ "paste", ] +[[package]] +name = "mimalloc" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68914350ae34959d83f732418d51e2427a794055d0b9529f48259ac07af65633" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "mime" version = "0.3.17" @@ -2849,6 +2868,7 @@ dependencies = [ "crossterm", "enable-ansi-support", "memmap2", + "mimalloc", "objdiff-core", "prost", "ratatui", diff --git a/objdiff-cli/Cargo.toml b/objdiff-cli/Cargo.toml index 0b33210..46210d2 100644 --- a/objdiff-cli/Cargo.toml +++ b/objdiff-cli/Cargo.toml @@ -28,3 +28,6 @@ supports-color = "3.0" time = { version = "0.3", features = ["formatting", "local-offset"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } + +[target.'cfg(target_env = "musl")'.dependencies] +mimalloc = "0.1" diff --git a/objdiff-cli/src/main.rs b/objdiff-cli/src/main.rs index 7a5acf0..7485419 100644 --- a/objdiff-cli/src/main.rs +++ b/objdiff-cli/src/main.rs @@ -2,6 +2,12 @@ mod argp_version; mod cmd; mod util; +// musl's allocator is very slow, so use mimalloc when targeting musl. +// Otherwise, use the system allocator to avoid extra code size. +#[cfg(target_env = "musl")] +#[global_allocator] +static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; + use std::{env, ffi::OsStr, fmt::Display, path::PathBuf, str::FromStr}; use anyhow::{Error, Result};