Skip to content

Commit 640d7bc

Browse files
authored
Turbopack: add manual worker count override (#84454)
1 parent 0f781a6 commit 640d7bc

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ inherits = "release"
254254
debug-assertions = true
255255
overflow-checks = true
256256

257+
[profile.release-with-debug]
258+
inherits = "release"
259+
debug = true
260+
257261
[workspace.dependencies]
258262
# Workspace crates
259263
next-api = { path = "crates/next-api" }

turbopack/crates/turbopack-cli/benches/small_apps.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ fn bench_small_apps(c: &mut Criterion) {
7474
log_detail: false,
7575
full_stats: false,
7676
target: None,
77+
worker_threads: None,
7778
},
7879
no_sourcemap: false,
7980
no_minify: false,

turbopack/crates/turbopack-cli/src/arguments.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ impl Arguments {
2525
Arguments::Dev(args) => args.common.dir.as_deref(),
2626
}
2727
}
28+
29+
/// The number of worker threads to use. see [CommonArguments]::worker_threads
30+
pub fn worker_threads(&self) -> Option<usize> {
31+
match self {
32+
Arguments::Build(args) => args.common.worker_threads,
33+
Arguments::Dev(args) => args.common.worker_threads,
34+
}
35+
}
2836
}
2937

3038
#[derive(
@@ -80,13 +88,17 @@ pub struct CommonArguments {
8088
#[clap(long)]
8189
pub full_stats: bool,
8290

91+
/// Whether to build for the `browser` or `node`
92+
#[clap(long)]
93+
pub target: Option<Target>,
94+
95+
/// Number of worker threads to use for parallel processing
96+
#[clap(long)]
97+
pub worker_threads: Option<usize>,
8398
// Enable experimental garbage collection with the provided memory limit in
8499
// MB.
85100
// #[clap(long)]
86101
// pub memory_limit: Option<usize>,
87-
/// Whether to build for the `browser` or `node``
88-
#[clap(long)]
89-
pub target: Option<Target>,
90102
}
91103

92104
#[derive(Debug, Args)]

turbopack/crates/turbopack-cli/src/main.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,25 @@ fn main() {
4242
});
4343
});
4444

45-
let worker_threads = available_parallelism().map(|n| n.get()).unwrap_or(1);
45+
let args = Arguments::parse();
46+
47+
let worker_threads = args
48+
.worker_threads()
49+
.map(|v| {
50+
if v == 0 {
51+
panic!("--worker-threads=0 is invalid, you must use at least one thread.");
52+
} else {
53+
v
54+
}
55+
})
56+
.unwrap_or_else(|| available_parallelism().map(|n| n.get()).unwrap_or(1));
4657

4758
rt.worker_threads(worker_threads);
4859
rt.max_blocking_threads(usize::MAX - worker_threads);
4960

5061
#[cfg(not(codspeed))]
5162
rt.disable_lifo_slot();
5263

53-
let args = Arguments::parse();
5464
rt.build().unwrap().block_on(main_inner(args)).unwrap();
5565
}
5666

0 commit comments

Comments
 (0)