Skip to content

Commit

Permalink
[Turbopack] disable lifo slot to make all tasks stealable (#75472)
Browse files Browse the repository at this point in the history
### What?

* pass rustflags to windows too
* disable lifo slot to make all tasks stealable

### Why?

Since we do a lot of CPU bound work in tokio tasks this can lead to future polling taking several seconds. With the lifo slot, one task is not stealable and need to wait for these several seconds to be executed. This delays that task and causes reduced parallelization of tasks.
  • Loading branch information
sokra authored Jan 30, 2025
1 parent a0f5959 commit 9a6b0f5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
16 changes: 14 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,22 @@ rustdocflags = []

[target.x86_64-pc-windows-msvc]
linker = "rust-lld"
rustflags = ["-C", "target-feature=+crt-static"]
rustflags = [
"--cfg",
"tokio_unstable",
"-Zshare-generics=y",
"-C",
"target-feature=+crt-static"
]

[target.i686-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
rustflags = [
"--cfg",
"tokio_unstable",
"-Zshare-generics=y",
"-C",
"target-feature=+crt-static"
]

[target.aarch64-pc-windows-msvc]
linker = "rust-lld"
Expand Down
12 changes: 12 additions & 0 deletions crates/napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,25 @@ static ALLOC: dhat::Alloc = dhat::Alloc;
#[napi::module_init]

fn init() {
use tokio::runtime::Builder;
use turbo_tasks_malloc::TurboMalloc;

set_hook(Box::new(|panic_info| {
util::log_internal_error_and_inform(&format!(
"Panic: {}\nBacktrace: {:?}",
panic_info,
Backtrace::new()
));
}));
let rt = Builder::new_multi_thread()
.enable_all()
.on_thread_stop(|| {
TurboMalloc::thread_stop();
})
.disable_lifo_slot()

Check failure on line 94 in crates/napi/src/lib.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-unknown-linux-musl - node@16

no method named `disable_lifo_slot` found for mutable reference `&mut tokio::runtime::Builder` in the current scope

Check failure on line 94 in crates/napi/src/lib.rs

View workflow job for this annotation

GitHub Actions / stable - aarch64-unknown-linux-musl - node@16

no method named `disable_lifo_slot` found for mutable reference `&mut tokio::runtime::Builder` in the current scope
.build()
.unwrap();
create_custom_tokio_runtime(rt);
}

#[inline]
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 @@ -29,6 +29,7 @@ fn main() {
.on_thread_stop(|| {
TurboMalloc::thread_stop();
})
.disable_lifo_slot()
.build()
.unwrap()
.block_on(main_inner(args))
Expand Down

0 comments on commit 9a6b0f5

Please sign in to comment.