Skip to content

Commit 5974ee3

Browse files
authored
chore: add pnp resolve benchmark (#71)
1 parent c6226fa commit 5974ee3

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

benches/resolver.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,26 @@ fn bench_resolver(c: &mut Criterion) {
232232
});
233233
},
234234
);
235+
236+
let pnp_workspace = env::current_dir().unwrap().join("fixtures/pnp");
237+
let root_range = 1..11;
238+
239+
group.bench_with_input(BenchmarkId::from_parameter("pnp resolve"), &root_range, |b, data| {
240+
let runner = runtime::Runtime::new().expect("failed to create tokio runtime");
241+
let oxc_resolver = Arc::new(oxc_resolver());
242+
243+
b.to_async(runner).iter_with_setup(
244+
|| {
245+
oxc_resolver.clear_cache();
246+
},
247+
|_| async {
248+
for i in data.clone() {
249+
let _ =
250+
oxc_resolver.resolve(pnp_workspace.join(format!("{i}")), "preact").await;
251+
}
252+
},
253+
);
254+
});
235255
}
236256

237257
criterion_group!(resolver, bench_resolver);

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
171171
/// Clear the underlying cache.
172172
pub fn clear_cache(&self) {
173173
self.cache.clear();
174+
#[cfg(feature = "yarn_pnp")]
175+
self.pnp_cache.clear();
174176
}
175177

176178
/// Resolve `specifier` at an absolute path to a `directory`.

0 commit comments

Comments
 (0)