-
-
Notifications
You must be signed in to change notification settings - Fork 35.8k
vfs: integrate with CJS and ESM module loaders #63653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mcollina
wants to merge
8
commits into
nodejs:main
Choose a base branch
from
mcollina:vfs-module-loader-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,153
−99
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
82e8cb5
vfs: integrate with CJS and ESM module loaders
mcollina 8b1b4ea
vfs: fix module loader paths on Windows
mcollina c65d084
vfs: scope-purge loader caches via per-VFS owned-keys sets
mcollina 692fee6
vfs: always allocate a fresh stat cache in clearStatCache
mcollina e5430da
vfs: anchor vfs-layer URL tag match in urlBelongsToLayer
mcollina 9941088
vfs: drop cache-busting/HMR reference from vfs-layer tag comment
mcollina 849e9f7
benchmark: add VFS fs-dispatch overhead bench
mcollina 9e2df52
vfs: hoist path normalization out of dispatch loop
mcollina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| 'use strict'; | ||
|
|
||
| // Measures the dispatch overhead the VFS layer adds to fs operations | ||
| // against real-filesystem paths (paths that no VFS claims). The hot | ||
| // path in lib/fs.js is: | ||
| // | ||
| // const h = vfsState.handlers; | ||
| // if (h !== null) { const r = h.opSync(path, ...); if (r !== undefined) return r; } | ||
| // binding.op(getValidatedPath(path)); | ||
| // | ||
| // With layers=0 the VFS module is never required and `h === null` is | ||
| // the first thing fs sees. With layers>=1 the handler walks | ||
| // activeVFSList calling vfs.shouldHandle(path) on each. The benchmark | ||
| // mounts N VFSes at distinct, unrelated mount points and probes a real | ||
| // file under __dirname, so every call falls through after the VFS list | ||
| // declines the path. That isolates per-layer dispatch cost. | ||
|
|
||
| const common = require('../common.js'); | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const bench = common.createBenchmark(main, { | ||
| n: [3e5], | ||
| op: ['statSync', 'existsSync', 'accessSync', 'readFileSync'], | ||
| // 0 = VFS module never loaded (true baseline) | ||
| // >=1 = that many VFS instances mounted at unrelated paths | ||
| layers: [0, 1, 2, 5, 10], | ||
| }, { | ||
| flags: ['--experimental-vfs', '--no-warnings'], | ||
| }); | ||
|
|
||
| function mountLayers(count) { | ||
| const vfs = require('node:vfs'); | ||
| const handles = []; | ||
| for (let i = 0; i < count; i++) { | ||
| const v = vfs.create(); | ||
| v.mount(`/vfs-bench-${i}`); | ||
| handles.push(v); | ||
| } | ||
| return handles; | ||
| } | ||
|
|
||
| function main({ n, op, layers }) { | ||
| const handles = layers > 0 ? mountLayers(layers) : null; | ||
|
|
||
| const target = layers === 0 ? __filename : path.join(__dirname, path.basename(__filename)); | ||
|
|
||
| // Warm-up - get the JIT past the first-call icache + IC misses so we | ||
| // measure steady-state dispatch cost, not first-call resolution. | ||
| for (let i = 0; i < 1000; i++) { | ||
| if (op === 'statSync') fs.statSync(target); | ||
| else if (op === 'existsSync') fs.existsSync(target); | ||
| else if (op === 'accessSync') fs.accessSync(target); | ||
| else fs.readFileSync(target); | ||
| } | ||
|
|
||
| bench.start(); | ||
| if (op === 'statSync') { | ||
| for (let i = 0; i < n; i++) fs.statSync(target); | ||
| } else if (op === 'existsSync') { | ||
| for (let i = 0; i < n; i++) fs.existsSync(target); | ||
| } else if (op === 'accessSync') { | ||
| for (let i = 0; i < n; i++) fs.accessSync(target); | ||
| } else { | ||
| for (let i = 0; i < n; i++) fs.readFileSync(target); | ||
| } | ||
| bench.end(n); | ||
|
|
||
| if (handles) { | ||
| for (const v of handles) v.unmount(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better not to document the cache behavior at length in case this changes and the documented behavior a maintenance burden. Caching should be considered internal details, although module URLs are observable and it's okay to document the changes.