Skip to content

Commit 24f58e4

Browse files
committed
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 (~14% of total instructions in the resolver callgrind bench). 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.
1 parent 02dbd01 commit 24f58e4

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

src/file_system.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ impl FileSystem for FileSystemOs {
153153
if self.options.enable_pnp {
154154
return match VPath::from(path)? {
155155
VPath::Zip(info) => self.pnp_lru.read(info.physical_base_path(), info.zip_path),
156-
VPath::Virtual(info) => tokio::fs::read(info.physical_base_path()).await,
157-
VPath::Native(path) => tokio::fs::read(&path).await,
156+
VPath::Virtual(info) => fs::read(info.physical_base_path()),
157+
VPath::Native(path) => fs::read(&path),
158158
}
159159
}
160160
}}
161161

162-
tokio::fs::read(path).await
162+
fs::read(path)
163163
}
164164

165165
async fn read_to_string(&self, path: &Path) -> io::Result<String> {
@@ -168,13 +168,13 @@ impl FileSystem for FileSystemOs {
168168
if self.options.enable_pnp {
169169
return match VPath::from(path)? {
170170
VPath::Zip(info) => self.pnp_lru.read_to_string(info.physical_base_path(), info.zip_path),
171-
VPath::Virtual(info) => tokio::fs::read_to_string(info.physical_base_path()).await,
172-
VPath::Native(path) => tokio::fs::read_to_string(&path).await,
171+
VPath::Virtual(info) => fs::read_to_string(info.physical_base_path()),
172+
VPath::Native(path) => fs::read_to_string(&path),
173173
}
174174
}
175175
}
176176
}
177-
tokio::fs::read_to_string(path).await
177+
fs::read_to_string(path)
178178
}
179179

180180
async fn metadata(&self, path: &Path) -> io::Result<FileMetadata> {
@@ -187,23 +187,19 @@ impl FileSystem for FileSystemOs {
187187
.file_type(info.physical_base_path(), info.zip_path)
188188
.map(FileMetadata::from),
189189
VPath::Virtual(info) => {
190-
tokio::fs::metadata(info.physical_base_path())
191-
.await
192-
.map(FileMetadata::from)
190+
fs::metadata(info.physical_base_path()).map(FileMetadata::from)
193191
}
194-
VPath::Native(path) => tokio::fs::metadata(path).await.map(FileMetadata::from),
192+
VPath::Native(path) => fs::metadata(path).map(FileMetadata::from),
195193
}
196194
}
197195
}
198196
}
199197

200-
tokio::fs::metadata(path).await.map(FileMetadata::from)
198+
fs::metadata(path).map(FileMetadata::from)
201199
}
202200

203201
async fn symlink_metadata(&self, path: &Path) -> io::Result<FileMetadata> {
204-
tokio::fs::symlink_metadata(path)
205-
.await
206-
.map(FileMetadata::from)
202+
fs::symlink_metadata(path).map(FileMetadata::from)
207203
}
208204

209205
async fn canonicalize(&self, path: &Path) -> io::Result<PathBuf> {

0 commit comments

Comments
 (0)