Skip to content
Draft
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
29 changes: 29 additions & 0 deletions benches/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,35 @@ fn bench_resolver(c: &mut Criterion) {
},
);

// Models the `@rspack/resolver` (NAPI) `.sync()` entry point — the common npm
// path — which runs one `Handle::current().block_on(resolve(...))` per call.
// Unlike `single-thread` (a single async block over the whole batch), every
// resolve enters and exits the runtime on its own, matching how a synchronous
// consumer (rspack injecting the resolver, or a direct `.sync()` caller)
// actually invokes it.
Comment on lines +287 to +292
group.bench_with_input(
BenchmarkId::from_parameter("napi-sync (block_on per resolve)"),
&data,
|b, data| {
let runner = runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("failed to create tokio runtime");
Comment on lines +297 to +300

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use the NAPI runtime type for this benchmark

For native npm users, napi-rs 3.9.0 creates its default runtime with Builder::new_multi_thread(), and within_runtime_if_available enters that runtime before Handle::current().block_on; this benchmark instead uses a current-thread runtime. This changes scheduling and tokio::fs/spawn_blocking behavior, so the scenario labeled as mirroring NAPI .sync() can produce performance results that do not represent the path it is intended to track. Construct the same multi-thread runtime as napi-rs (and ideally enter it as the wrapper does) before measuring per-call block_on.

Useful? React with 👍 / 👎.

let rspack_resolver = rspack_resolver(false);

b.iter_with_setup(
|| {
rspack_resolver.clear_cache();
},
|_| {
for (path, request) in data {
let _ = runner.block_on(rspack_resolver.resolve(path, request));
}
},
);
},
);

group.bench_with_input(
BenchmarkId::from_parameter("[single-threaded]resolve with many extensions"),
&data,
Expand Down
Loading