summaryrefslogtreecommitdiff
path: root/lib/module.js
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2016-10-19 21:43:36 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2016-10-24 22:50:44 +0200
commit678c094357c8656a26bb3f7348fac02e3ecc2a88 (patch)
treedb39fba0eaeea4389ed6d5b6da002440e7f9e353 /lib/module.js
parentdf29d9f5004a6d88603a9435782f4d7fcbcb3153 (diff)
downloadandroid-node-v8-678c094357c8656a26bb3f7348fac02e3ecc2a88.tar.gz
android-node-v8-678c094357c8656a26bb3f7348fac02e3ecc2a88.tar.bz2
android-node-v8-678c094357c8656a26bb3f7348fac02e3ecc2a88.zip
module: skip directories known not to exist
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: https://github.com/nodejs/node/pull/9196 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/module.js')
-rw-r--r--lib/module.js6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/module.js b/lib/module.js
index 2d886d8a52..bc9d11ee0b 100644
--- a/lib/module.js
+++ b/lib/module.js
@@ -171,8 +171,8 @@ Module._findPath = function(request, paths, isMain) {
var basePath = path.resolve(curPath, request);
var filename;
+ const rc = stat(basePath);
if (!trailingSlash) {
- const rc = stat(basePath);
if (rc === 0) { // File.
if (preserveSymlinks && !isMain) {
filename = path.resolve(basePath);
@@ -193,13 +193,13 @@ Module._findPath = function(request, paths, isMain) {
}
}
- if (!filename) {
+ if (!filename && rc === 1) { // Directory.
if (exts === undefined)
exts = Object.keys(Module._extensions);
filename = tryPackage(basePath, exts, isMain);
}
- if (!filename) {
+ if (!filename && rc === 1) { // Directory.
// try it with each of the extensions at "index"
if (exts === undefined)
exts = Object.keys(Module._extensions);