From e66a5ab6d3f1ed8e0969c9895b3ff647d0166a27 Mon Sep 17 00:00:00 2001 From: pshu Date: Wed, 10 Jun 2026 10:54:14 +0800 Subject: [PATCH 1/2] chore(perf): FileSystemOs uses std::fs instead of tokio::fs tokio::fs offloads every syscall to the blocking threadpool (semaphore + task harness + park/unpark). Resolution issues a large number of tiny stat/read calls whose kernel time is dwarfed by that per-call scheduling overhead. std::fs runs them inline, matching the existing wasm impl and the upstream synchronous resolver. This only affects the default FileSystemOs (the @rspack/resolver npm package and the bench). rspack core injects its own async BoxFS via new_with_file_system, so its real resolution fs path is unchanged. --- src/file_system.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/file_system.rs b/src/file_system.rs index feaeaa92..ec774bc3 100644 --- a/src/file_system.rs +++ b/src/file_system.rs @@ -153,13 +153,13 @@ impl FileSystem for FileSystemOs { if self.options.enable_pnp { return match VPath::from(path)? { VPath::Zip(info) => self.pnp_lru.read(info.physical_base_path(), info.zip_path), - VPath::Virtual(info) => tokio::fs::read(info.physical_base_path()).await, - VPath::Native(path) => tokio::fs::read(&path).await, + VPath::Virtual(info) => fs::read(info.physical_base_path()), + VPath::Native(path) => fs::read(&path), } } }} - tokio::fs::read(path).await + fs::read(path) } async fn read_to_string(&self, path: &Path) -> io::Result { @@ -168,13 +168,13 @@ impl FileSystem for FileSystemOs { if self.options.enable_pnp { return match VPath::from(path)? { VPath::Zip(info) => self.pnp_lru.read_to_string(info.physical_base_path(), info.zip_path), - VPath::Virtual(info) => tokio::fs::read_to_string(info.physical_base_path()).await, - VPath::Native(path) => tokio::fs::read_to_string(&path).await, + VPath::Virtual(info) => fs::read_to_string(info.physical_base_path()), + VPath::Native(path) => fs::read_to_string(&path), } } } } - tokio::fs::read_to_string(path).await + fs::read_to_string(path) } async fn metadata(&self, path: &Path) -> io::Result { @@ -187,23 +187,19 @@ impl FileSystem for FileSystemOs { .file_type(info.physical_base_path(), info.zip_path) .map(FileMetadata::from), VPath::Virtual(info) => { - tokio::fs::metadata(info.physical_base_path()) - .await - .map(FileMetadata::from) + fs::metadata(info.physical_base_path()).map(FileMetadata::from) } - VPath::Native(path) => tokio::fs::metadata(path).await.map(FileMetadata::from), + VPath::Native(path) => fs::metadata(path).map(FileMetadata::from), } } } } - tokio::fs::metadata(path).await.map(FileMetadata::from) + fs::metadata(path).map(FileMetadata::from) } async fn symlink_metadata(&self, path: &Path) -> io::Result { - tokio::fs::symlink_metadata(path) - .await - .map(FileMetadata::from) + fs::symlink_metadata(path).map(FileMetadata::from) } async fn canonicalize(&self, path: &Path) -> io::Result { From 6893efb0b24d52ed7e42a6bab5e226fc6d204201 Mon Sep 17 00:00:00 2001 From: pshu Date: Wed, 10 Jun 2026 10:54:18 +0800 Subject: [PATCH 2/2] chore(deps): drop unused tokio "fs" feature Nothing references tokio::fs after FileSystemOs moved to std::fs; the wasm target already builds without it. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 715956e5..288cbef3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -100,7 +100,7 @@ document-features = { version = "0.2.12", optional = true } futures = "0.3.32" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -tokio = { version = "1.52.3", default-features = false, features = ["sync", "rt-multi-thread", "macros", "fs"] } +tokio = { version = "1.52.3", default-features = false, features = ["sync", "rt-multi-thread", "macros"] } [target.'cfg(target_arch = "wasm32")'.dependencies] tokio = { version = "1.52.3", default-features = false, features = ["sync", "rt", "macros"] }