Skip to content

Commit 219fcf6

Browse files
committed
perf(turbopack): use forked mimalloc on wasm
1 parent 76167ad commit 219fcf6

File tree

3 files changed

+26
-44
lines changed

3 files changed

+26
-44
lines changed

Cargo.lock

Lines changed: 15 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbo-tasks-malloc/Cargo.toml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@ autobenches = false
99
[lib]
1010
bench = false
1111

12-
[dependencies]
13-
rspack-libmimalloc-sys = { version = "0.2.4", default-features = false, features = [], optional = true }
14-
15-
[target.'cfg(not(any(target_os = "linux", target_family = "wasm", target_env = "musl")))'.dependencies]
16-
mimalloc-rspack = { version = "0.2.4", features = [
12+
[target.'cfg(not(any(target_os = "linux", target_env = "musl")))'.dependencies]
13+
mimalloc = { git = "https://github.com/utooland/mimalloc_rust.git", features = [
1714
"v3",
1815
"extended"
1916
], optional = true }
2017

21-
[target.'cfg(all(target_os = "linux", not(any(target_family = "wasm", target_env = "musl"))))'.dependencies]
22-
mimalloc-rspack = { version = "0.2.4", features = [
18+
[target.'cfg(all(target_os = "linux", not(target_env = "musl")))'.dependencies]
19+
mimalloc = { git = "https://github.com/utooland/mimalloc_rust.git", features = [
2320
"v3",
2421
"extended",
2522
"local_dynamic_tls",
2623
], optional = true }
2724

2825
[features]
29-
custom_allocator = ["dep:mimalloc-rspack", "dep:rspack-libmimalloc-sys"]
26+
custom_allocator = ["dep:mimalloc"]
3027
default = ["custom_allocator"]

turbopack/crates/turbo-tasks-malloc/src/lib.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,29 +114,17 @@ impl TurboMalloc {
114114
/// Get the allocator for this platform that we should wrap with TurboMalloc.
115115
#[inline]
116116
fn base_alloc() -> &'static impl GlobalAlloc {
117-
#[cfg(all(
118-
feature = "custom_allocator",
119-
not(any(target_family = "wasm", target_env = "musl"))
120-
))]
121-
return &mimalloc_rspack::MiMalloc;
122-
#[cfg(any(
123-
not(feature = "custom_allocator"),
124-
any(target_family = "wasm", target_env = "musl")
125-
))]
117+
#[cfg(all(feature = "custom_allocator", not(target_env = "musl")))]
118+
return &mimalloc::MiMalloc;
119+
#[cfg(any(not(feature = "custom_allocator"), target_env = "musl"))]
126120
return &std::alloc::System;
127121
}
128122

129123
#[allow(unused_variables)]
130124
unsafe fn base_alloc_size(ptr: *const u8, layout: Layout) -> usize {
131-
#[cfg(all(
132-
feature = "custom_allocator",
133-
not(any(target_family = "wasm", target_env = "musl"))
134-
))]
135-
return unsafe { mimalloc_rspack::MiMalloc.usable_size(ptr) };
136-
#[cfg(any(
137-
not(feature = "custom_allocator"),
138-
any(target_family = "wasm", target_env = "musl")
139-
))]
125+
#[cfg(all(feature = "custom_allocator", not(target_env = "musl")))]
126+
return unsafe { mimalloc::MiMalloc.usable_size(ptr) };
127+
#[cfg(any(not(feature = "custom_allocator"), target_env = "musl"))]
140128
return layout.size();
141129
}
142130

0 commit comments

Comments
 (0)