Commit 133a8a1
committed
vfs: hoist path normalization out of dispatch loop
VirtualFileSystem#shouldHandle was recomputing both
toNamespacedPath(resolve(mountPoint)) AND
toNamespacedPath(resolve(inputPath)) on every fs call, for every
active VFS. With N mounted layers this meant 2N path normalizations
per fs op against a real-filesystem path that no VFS owns.
Cache the normalized mount point on the VFS instance at mount time,
and add a shouldHandleNormalized fast path that takes an
already-normalized input. The setup.js dispatch helpers
(findVFSForStat / findVFSForRead / findVFSForExists / findVFSForPath /
findVFSWith / findVFSPackageJSON / legacyMainResolve /
getLayerForPath) now normalize the input once before the walk and
share it across every layer.
Benchmarked with benchmark/vfs/bench-fs-dispatch.js on a
real-filesystem target path under 0/1/2/5/10 mounted layers:
op layers=10 before layers=10 after speedup
statSync 96k ops/s 278k ops/s 2.9x
existsSync 99k ops/s 315k ops/s 3.2x
accessSync 98k ops/s 309k ops/s 3.2x
readFileSync 42k ops/s 99k ops/s 2.4x
Per-additional-layer cost drops from ~860 ns to ~80 ns for
stat/exists/access (and from ~1700 ns to ~200 ns for readFile).
The layers=0 (VFS not loaded) path is unaffected: vfsState.handlers
stays null and fs ops short-circuit on a single null check.
Signed-off-by: Matteo Collina <hello@matteocollina.com>1 parent 7bedf50 commit 133a8a1
2 files changed
Lines changed: 53 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
| |||
119 | 123 | | |
120 | 124 | | |
121 | 125 | | |
| 126 | + | |
122 | 127 | | |
123 | 128 | | |
124 | 129 | | |
| |||
180 | 185 | | |
181 | 186 | | |
182 | 187 | | |
| 188 | + | |
183 | 189 | | |
184 | 190 | | |
185 | 191 | | |
| |||
195 | 201 | | |
196 | 202 | | |
197 | 203 | | |
| 204 | + | |
198 | 205 | | |
199 | 206 | | |
200 | 207 | | |
| |||
214 | 221 | | |
215 | 222 | | |
216 | 223 | | |
217 | | - | |
| 224 | + | |
| 225 | + | |
218 | 226 | | |
219 | 227 | | |
220 | | - | |
221 | | - | |
222 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
223 | 245 | | |
224 | 246 | | |
225 | 247 | | |
| |||
280 | 302 | | |
281 | 303 | | |
282 | 304 | | |
283 | | - | |
| 305 | + | |
| 306 | + | |
284 | 307 | | |
285 | | - | |
286 | 308 | | |
287 | 309 | | |
288 | 310 | | |
| |||
1359 | 1381 | | |
1360 | 1382 | | |
1361 | 1383 | | |
| 1384 | + | |
1362 | 1385 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
241 | 242 | | |
242 | 243 | | |
243 | 244 | | |
| 245 | + | |
| 246 | + | |
244 | 247 | | |
245 | 248 | | |
246 | | - | |
| 249 | + | |
247 | 250 | | |
248 | 251 | | |
249 | 252 | | |
| |||
258 | 261 | | |
259 | 262 | | |
260 | 263 | | |
| 264 | + | |
| 265 | + | |
261 | 266 | | |
262 | 267 | | |
263 | | - | |
| 268 | + | |
264 | 269 | | |
265 | 270 | | |
266 | 271 | | |
| |||
357 | 362 | | |
358 | 363 | | |
359 | 364 | | |
| 365 | + | |
360 | 366 | | |
361 | 367 | | |
362 | | - | |
| 368 | + | |
363 | 369 | | |
364 | 370 | | |
365 | 371 | | |
| |||
376 | 382 | | |
377 | 383 | | |
378 | 384 | | |
| 385 | + | |
| 386 | + | |
379 | 387 | | |
380 | 388 | | |
381 | | - | |
| 389 | + | |
382 | 390 | | |
383 | 391 | | |
384 | 392 | | |
385 | 393 | | |
386 | 394 | | |
387 | 395 | | |
388 | 396 | | |
| 397 | + | |
| 398 | + | |
389 | 399 | | |
390 | 400 | | |
391 | | - | |
| 401 | + | |
392 | 402 | | |
393 | 403 | | |
394 | 404 | | |
| |||
397 | 407 | | |
398 | 408 | | |
399 | 409 | | |
| 410 | + | |
| 411 | + | |
400 | 412 | | |
401 | 413 | | |
402 | | - | |
| 414 | + | |
403 | 415 | | |
404 | 416 | | |
405 | 417 | | |
| |||
961 | 973 | | |
962 | 974 | | |
963 | 975 | | |
| 976 | + | |
| 977 | + | |
964 | 978 | | |
965 | 979 | | |
966 | | - | |
| 980 | + | |
967 | 981 | | |
968 | 982 | | |
969 | 983 | | |
| |||
1023 | 1037 | | |
1024 | 1038 | | |
1025 | 1039 | | |
| 1040 | + | |
| 1041 | + | |
1026 | 1042 | | |
1027 | 1043 | | |
1028 | | - | |
| 1044 | + | |
1029 | 1045 | | |
1030 | 1046 | | |
1031 | 1047 | | |
| |||
0 commit comments