Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/next-build-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ fn main() {
*cell = Some(Instant::now());
}
});
TurboMalloc::thread_park();
})
.build()
.unwrap()
Expand Down
1 change: 1 addition & 0 deletions crates/next-napi-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ fn init() {
*cell = Some(Instant::now());
}
});
TurboMalloc::thread_park();
})
.worker_threads(worker_threads)
// Avoid a limit on threads to avoid deadlocks due to usage of block_in_place
Expand Down
3 changes: 3 additions & 0 deletions turbopack/crates/turbo-tasks-backend/fuzz/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ static RUNTIME: Lazy<tokio::runtime::Runtime> = Lazy::new(|| {
.on_thread_stop(|| {
TurboMalloc::thread_stop();
})
.on_thread_park(|| {
TurboMalloc::thread_park();
})
.build()
.unwrap()
});
Expand Down
6 changes: 5 additions & 1 deletion turbopack/crates/turbo-tasks-malloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ bench = false

[dependencies]

[target.'cfg(not(target_family = "wasm"))'.dependencies]
libmimalloc-sys = { version = "0.1.44", features = [
"extended",
], optional = true }

[target.'cfg(not(any(target_os = "linux", target_family = "wasm")))'.dependencies]
mimalloc = { version = "0.1.48", features = [
Expand All @@ -26,5 +30,5 @@ mimalloc = { version = "0.1.48", features = [
], optional = true }

[features]
custom_allocator = ["dep:mimalloc"]
custom_allocator = ["dep:mimalloc", "dep:libmimalloc-sys"]
default = ["custom_allocator"]
7 changes: 7 additions & 0 deletions turbopack/crates/turbo-tasks-malloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ impl TurboMalloc {
flush();
}

pub fn thread_park() {
#[cfg(all(feature = "custom_allocator", not(target_family = "wasm")))]
unsafe {
libmimalloc_sys::mi_collect(false);
}
}

pub fn allocation_counters() -> AllocationCounters {
self::counter::allocation_counters()
}
Expand Down
10 changes: 7 additions & 3 deletions turbopack/crates/turbopack-cli/benches/small_apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ fn bench_small_apps(c: &mut Criterion) {

b.iter(move || {
let mut rt = tokio::runtime::Builder::new_multi_thread();
rt.enable_all().on_thread_stop(|| {
TurboMalloc::thread_stop();
});
rt.enable_all()
.on_thread_stop(|| {
TurboMalloc::thread_stop();
})
.on_thread_park(|| {
TurboMalloc::thread_park();
});
let rt = rt.build().unwrap();

let apps_dir = apps_dir.clone();
Expand Down
1 change: 1 addition & 0 deletions turbopack/crates/turbopack-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn main() {
*cell = Some(Instant::now());
}
});
TurboMalloc::thread_park();
});

let args = Arguments::parse();
Expand Down
Loading