From a71ee93afeada095aaefb0656ef744c5bcc9e9ce Mon Sep 17 00:00:00 2001 From: Pierre Inglebert Date: Mon, 8 Jun 2015 23:44:18 +0200 Subject: [PATCH] module: reduce syscalls during require search require() now checks that the path exists before searching further in it. PR-URL: https://github.com/nodejs/io.js/pull/1920 Reviewed-By: Isaac Z. Schlueter Reviewed-By: Trevor Norris Reviewed-By: Chris Dickinson Reviewed-By: Jeremiah Senkpiel --- lib/module.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/module.js b/lib/module.js index 31f2063231dedc..9eba6bfdc15518 100644 --- a/lib/module.js +++ b/lib/module.js @@ -129,7 +129,7 @@ const noopDeprecateRequireDot = util.deprecate(function() {}, Module._findPath = function(request, paths) { var exts = Object.keys(Module._extensions); - if (request.charAt(0) === '/') { + if (path.isAbsolute(request)) { paths = ['']; } @@ -142,6 +142,8 @@ Module._findPath = function(request, paths) { // For each path for (var i = 0, PL = paths.length; i < PL; i++) { + // Don't search further if path doesn't exist + if (paths[i] && internalModuleStat(paths[i]) < 1) continue; var basePath = path.resolve(paths[i], request); var filename;