From 452c68de199b3db8ab960785a70425c902b83721 Mon Sep 17 00:00:00 2001 From: pshu Date: Mon, 17 Nov 2025 17:36:44 +0800 Subject: [PATCH 1/2] perf: base line --- benches/resolver.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/benches/resolver.rs b/benches/resolver.rs index 55cd118..4b89165 100644 --- a/benches/resolver.rs +++ b/benches/resolver.rs @@ -8,6 +8,7 @@ use std::{ }; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; +use rspack_resolver::{ResolveOptions, Resolver}; use serde_json::Value; use tokio::{ runtime::{self, Builder}, @@ -91,6 +92,33 @@ fn rspack_resolver() -> rspack_resolver::Resolver { }) } +fn resolver_with_many_extensions() -> rspack_resolver::Resolver { + Resolver::new(ResolveOptions { + extensions: vec![ + ".bad0".to_string(), + ".bad1".to_string(), + ".bad2".to_string(), + ".bad4".to_string(), + ".bad6".to_string(), + ".bad5".to_string(), + ".bad6".to_string(), + ".bad7".to_string(), + ".bad8".to_string(), + ".bad9".to_string(), + ".mtsx".to_string(), + ".mts".to_string(), + ".mjs".to_string(), + ".tsx".to_string(), + ".ts".to_string(), + ".jsx".to_string(), + ".js".to_string(), + ], + imports_fields: vec![], + exports_fields: vec![], + ..Default::default() + }) +} + fn create_async_resolve_task( rspack_resolver: Arc, path: PathBuf, @@ -183,6 +211,30 @@ fn bench_resolver(c: &mut Criterion) { }, ); + group.bench_with_input( + BenchmarkId::from_parameter("[single-threaded]resolve with many extensions"), + &data, + |b, data| { + let runner = runtime::Builder::new_current_thread() + .build() + .expect("failed to create tokio runtime"); + let rspack_resolver = resolver_with_many_extensions(); + + b.to_async(runner).iter_with_setup( + || { + rspack_resolver.clear_cache(); + }, + |_| async { + for (path, request) in data { + _ = rspack_resolver + .resolve(path, &format!("{}/bad", request)) + .await; + } + }, + ); + }, + ); + group.bench_with_input( BenchmarkId::from_parameter("multi-thread"), &data, From 2b5ef1e1595c3e01ec0dc3d5aa67cc15f1bc7a6a Mon Sep 17 00:00:00 2001 From: pshu Date: Tue, 18 Nov 2025 09:04:40 +0800 Subject: [PATCH 2/2] refactor: sync bench code --- benches/resolver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benches/resolver.rs b/benches/resolver.rs index 4b89165..9fe8762 100644 --- a/benches/resolver.rs +++ b/benches/resolver.rs @@ -98,8 +98,8 @@ fn resolver_with_many_extensions() -> rspack_resolver::Resolver { ".bad0".to_string(), ".bad1".to_string(), ".bad2".to_string(), + ".bad3".to_string(), ".bad4".to_string(), - ".bad6".to_string(), ".bad5".to_string(), ".bad6".to_string(), ".bad7".to_string(),