Skip to content

Commit

Permalink
perf: use faster allocators (#2874)
Browse files Browse the repository at this point in the history
Co-authored-by: Ruben Arts <ruben.arts@hotmail.com>
  • Loading branch information
baszalmstra and ruben-arts authored Jan 14, 2025
1 parent 8f4bc4e commit 9e371c4
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 14 deletions.
59 changes: 48 additions & 11 deletions Cargo.lock

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

15 changes: 13 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -402,4 +413,4 @@ gcc-aarch64-linux-gnu = { version = '*', targets = [

# Package config for `dist`
[package.metadata.dist]
features = ["self_update"]
features = ["self_update", "performance"]
16 changes: 16 additions & 0 deletions crates/pixi_allocator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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" }
23 changes: 23 additions & 0 deletions crates/pixi_allocator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion crates/pixi_build_frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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()
Expand Down

0 comments on commit 9e371c4

Please sign in to comment.