-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
module: skip directories known not to exist #9196
Conversation
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.
LGTM
Here is what the access pattern looked liked before this pull request. (File paths shortened for brevity.)
Note how the last four are guaranteed to fail because of the first one. |
LGTM |
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.
LGTM
Does attempting to require from a directory, failing and making a new directory, writing into, and then loading files from that directory still work? |
You say 'still' but does it work now? The stat cache persists for the duration of a module's top-level code. |
@@ -69,6 +69,8 @@ assert.equal(threeFolder, threeIndex); | |||
assert.notEqual(threeFolder, three); | |||
|
|||
console.error('test package.json require() loading'); | |||
assert.equal(require('../fixtures/packages/index').ok, 'ok', |
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.
strictEqual
?
I know equal
is consistent with the rest of the test but updating the test may be worthwhile
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 followed the style of the surrounding code here.
EDIT: Never mind, didn't see you edited your comment. Still, consistency is important, right?
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'll update the test en bloc in a separate pull request.
EDIT: #9263
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.
LGTM with a nit
Verify that a package.json without a .main property loads index.js. PR-URL: nodejs#9196 Reviewed-By: Brian White <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]>
Discourage using require.extensions because it slows down the module loader. The number of file system operations that the module system has to perform in order to resolve a `require(...)` statement to a filename is proportional to the number of registered extensions. PR-URL: nodejs#9196 Reviewed-By: Brian White <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]>
There is no point in trying to search for files in a directory that we know does not exist, so stop doing that. Reduces the total number of stat(2) calls and the number of stat(2) misses on a medium-sized application by about 21% and 29% respectively. Reduces the total number of package.json open(2) calls and the number of open(2) misses by about 21% and 93% (!) respectively. Before: % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 50.93 0.178419 38 4702 lstat 29.08 0.101875 36 2800 2010 stat 11.36 0.039796 43 932 215 open 5.39 0.018897 34 550 fstat 3.24 0.011337 34 336 pread ------ ----------- ----------- --------- --------- ---------------- 100.00 0.350324 9320 2225 total After: % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 55.49 0.176638 38 4702 lstat 24.76 0.078826 35 2225 1435 stat 10.19 0.032434 44 733 16 open 6.19 0.019719 36 550 fstat 3.37 0.010723 32 336 pread ------ ----------- ----------- --------- --------- ---------------- 100.00 0.318340 8546 1451 total PR-URL: nodejs#9196 Reviewed-By: Brian White <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]>
8f5dfbc
to
678c094
Compare
Verify that a package.json without a .main property loads index.js. PR-URL: #9196 Reviewed-By: Brian White <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]>
There is no point in trying to search for files in a directory that we know does not exist, so stop doing that. Reduces the total number of stat(2) calls and the number of stat(2) misses on a medium-sized application by about 21% and 29% respectively. Reduces the total number of package.json open(2) calls and the number of open(2) misses by about 21% and 93% (!) respectively. Before: % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 50.93 0.178419 38 4702 lstat 29.08 0.101875 36 2800 2010 stat 11.36 0.039796 43 932 215 open 5.39 0.018897 34 550 fstat 3.24 0.011337 34 336 pread ------ ----------- ----------- --------- --------- ---------------- 100.00 0.350324 9320 2225 total After: % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 55.49 0.176638 38 4702 lstat 24.76 0.078826 35 2225 1435 stat 10.19 0.032434 44 733 16 open 6.19 0.019719 36 550 fstat 3.37 0.010723 32 336 pread ------ ----------- ----------- --------- --------- ---------------- 100.00 0.318340 8546 1451 total PR-URL: #9196 Reviewed-By: Brian White <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]>
Discourage using require.extensions because it slows down the module loader. The number of file system operations that the module system has to perform in order to resolve a `require(...)` statement to a filename is proportional to the number of registered extensions. PR-URL: #9196 Reviewed-By: Brian White <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]>
@bnoordhuis should this be backported? |
It could but it doesn't have to be. It's an optimization, not a bug fix. |
@bnoordhuis @MylesBorins should be labelled either |
It should be a zero-risk back-port but then again, no one complained it's slow. The most compelling reason would be to avoid future merge conflicts but OTOH, lib/module.js doesn't see all that many updates so probably not much of an issue. /stream-of-consciousness Don't bother, it's fine. |
I think we should just keep this labelled and be ready to backport if we run into problems in the future... would prefer not to touch module |
There is no point in trying to search for files in a directory that
we know does not exist, so stop doing that.
Reduces the total number of stat(2) calls and the number of stat(2)
misses on a medium-sized application by about 21% and 29% respectively.
Reduces the total number of package.json open(2) calls and the number
of open(2) misses by about 21% and 93% (!) respectively.
Before:
After:
CI: https://ci.nodejs.org/job/node-test-pull-request/4587/