diff --git a/Cargo.lock b/Cargo.lock index da1977327f5b..ec0d30bc6f73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3452,6 +3452,7 @@ name = "rspack_allocator" version = "0.1.0" dependencies = [ "mimalloc", + "tikv-jemallocator", ] [[package]] @@ -6531,6 +6532,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.36" diff --git a/crates/rspack_allocator/Cargo.toml b/crates/rspack_allocator/Cargo.toml index 0f3885e1441d..19bfba9e8bff 100644 --- a/crates/rspack_allocator/Cargo.toml +++ b/crates/rspack_allocator/Cargo.toml @@ -7,9 +7,9 @@ repository = "https://github.com/web-infra-dev/rspack" version = "0.1.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[target.'cfg(target_os = "linux")'.dependencies] +[target.'cfg(any(target_os = "linux", target_env = "msvc"))'.dependencies] # Turned on `local_dynamic_tls` to avoid issue: https://github.com/microsoft/mimalloc/issues/147 mimalloc = { workspace = true, features = ["local_dynamic_tls"] } -[target.'cfg(not(target_os = "linux"))'.dependencies] -mimalloc = { workspace = true } +[target.'cfg(not(any(target_os = "linux", target_env = "msvc")))'.dependencies] +tikv-jemallocator = "0.6" diff --git a/crates/rspack_allocator/src/lib.rs b/crates/rspack_allocator/src/lib.rs index 140529497708..651968dff4d7 100644 --- a/crates/rspack_allocator/src/lib.rs +++ b/crates/rspack_allocator/src/lib.rs @@ -1,4 +1,7 @@ -// use mimalloc::MiMalloc; +#[cfg(not(any(target_os = "linux", target_env = "msvc")))] +#[global_allocator] +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; -// #[global_allocator] -// static GLOBAL: MiMalloc = MiMalloc; +#[cfg(any(target_os = "linux", target_env = "msvc"))] +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;