diff --git a/Cargo.lock b/Cargo.lock index 4b02ba913..82bd40f77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -418,15 +418,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "backtrace-ext" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50" -dependencies = [ - "backtrace", -] - [[package]] name = "barrier_cell" version = "0.1.0" @@ -2811,6 +2802,16 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" +[[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.1.3" @@ -2954,8 +2955,6 @@ version = "7.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "317f146e2eb7021892722af37cf1b971f0a70c8406f487e24952667616192c64" dependencies = [ - "backtrace", - "backtrace-ext", "cfg-if", "miette-derive 7.4.0", "owo-colors", @@ -2991,6 +2990,15 @@ dependencies = [ "syn", ] +[[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" @@ -3672,6 +3680,7 @@ dependencies = [ "pep440_rs", "pep508_rs", "percent-encoding", + "pixi_allocator", "pixi_build_frontend", "pixi_build_types", "pixi_config", @@ -3747,6 +3756,14 @@ dependencies = [ "zstd", ] +[[package]] +name = "pixi_allocator" +version = "0.1.0" +dependencies = [ + "mimalloc", + "tikv-jemallocator", +] + [[package]] name = "pixi_build_frontend" version = "0.1.0" @@ -6140,6 +6157,26 @@ dependencies = [ "once_cell", ] +[[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.37" diff --git a/Cargo.toml b/Cargo.toml index d0833174e..43ccf790f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,9 @@ [workspace] +exclude = [ + # Only pulled in when enabling certain features. We do not want to include + # these crates when running workspace wide commands. + "crates/pixi_allocator", +] members = ["crates/*"] [workspace.package] @@ -51,7 +56,7 @@ itertools = "0.13.0" jsonrpsee = "=0.24.2" libc = { version = "0.2.169", default-features = false } memchr = "2.7.4" -miette = { version = "7.4.0", features = ["fancy"] } +miette = { version = "7.4.0" } minijinja = "2.5.0" nix = { version = "0.29.0", default-features = false } once_cell = "1.20.2" @@ -144,6 +149,7 @@ zip = { version = "2.2.2", default-features = false } zstd = { version = "0.13.2", default-features = false } fancy_display = { path = "crates/fancy_display" } +pixi_allocator = { path = "crates/pixi_allocator" } pixi_build_frontend = { path = "crates/pixi_build_frontend" } pixi_build_type_conversions = { path = "crates/pixi_build_type_conversions" } pixi_build_types = { path = "crates/pixi_build_types" } @@ -194,6 +200,10 @@ rustls-tls = [ self_update = [] slow_integration_tests = [] +# This feature enables performance optimizations but at the cost of increased +# compile times. By default, it is only used when building the release binary. +performance = ["pixi_allocator"] + [dependencies] ahash = { workspace = true } assert_matches = { workspace = true } @@ -260,6 +270,7 @@ uv-pep508 = { workspace = true } uv-pypi-types = { workspace = true } fs-err = { workspace = true, features = ["tokio"] } +pixi_allocator = { workspace = true, optional = true } pixi_build_frontend = { workspace = true } pixi_build_types = { workspace = true } pixi_config = { workspace = true } @@ -402,4 +413,4 @@ gcc-aarch64-linux-gnu = { version = '*', targets = [ # Package config for `dist` [package.metadata.dist] -features = ["self_update"] +features = ["self_update", "performance"] diff --git a/crates/pixi_allocator/Cargo.toml b/crates/pixi_allocator/Cargo.toml new file mode 100644 index 000000000..9d39d8989 --- /dev/null +++ b/crates/pixi_allocator/Cargo.toml @@ -0,0 +1,16 @@ +[package] +description = "A crate that provides the best memory allocator for different platforms" +edition = "2021" +name = "pixi_allocator" +version = "0.1.0" + +[lib] +doctest = false + +[dependencies] + +[target.'cfg(all(target_os = "windows"))'.dependencies] +mimalloc = { version = "0.1.43" } + +[target.'cfg(all(not(target_os = "windows"), not(target_os = "openbsd"), not(target_os = "freebsd"), any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "powerpc64")))'.dependencies] +tikv-jemallocator = { version = "0.6.0" } diff --git a/crates/pixi_allocator/src/lib.rs b/crates/pixi_allocator/src/lib.rs new file mode 100644 index 000000000..049d21ab5 --- /dev/null +++ b/crates/pixi_allocator/src/lib.rs @@ -0,0 +1,23 @@ +//! This crate pulls in specific allocators for different platforms to optimize +//! the performance. +//! +//! This is placed in a separate crate to easily allow conditional compilation. +//! Compiling these crates can take a long time and we do not always care about +//! the extra performance. + +#[cfg(target_os = "windows")] +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + +#[cfg(all( + not(target_os = "windows"), + not(target_os = "openbsd"), + not(target_os = "freebsd"), + any( + target_arch = "x86_64", + target_arch = "aarch64", + target_arch = "powerpc64" + ) +))] +#[global_allocator] +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; diff --git a/crates/pixi_build_frontend/Cargo.toml b/crates/pixi_build_frontend/Cargo.toml index 5cddf7c39..e21f2d3de 100644 --- a/crates/pixi_build_frontend/Cargo.toml +++ b/crates/pixi_build_frontend/Cargo.toml @@ -15,7 +15,7 @@ fs-err = { workspace = true, features = ["tokio"] } futures = { workspace = true } itertools = { workspace = true } jsonrpsee = { workspace = true, features = ["client"] } -miette = { workspace = true, features = ["fancy", "serde"] } +miette = { workspace = true, features = ["fancy-no-backtrace", "serde"] } pixi_build_type_conversions = { workspace = true } pixi_build_types = { path = "../pixi_build_types" } pixi_config = { workspace = true } diff --git a/src/main.rs b/src/main.rs index e91690239..94aeea7b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,8 @@ +// This forces the crate to be compiled even though the crate is not used in the project. +// https://github.com/rust-lang/rust/issues/64402 +#[cfg(feature = "pixi_allocator")] +extern crate pixi_allocator; + pub fn main() -> miette::Result<()> { let runtime = tokio::runtime::Builder::new_current_thread() .enable_all()