Permalink
Browse files

module: avoid JSON.stringify() for cache key

By avoiding JSON.stringify() and simply joining the strings with a
delimiter that does not appear in paths, we can improve cached
require() performance by at least 50%.

Additionally, this commit removes the last source of permanent
function deoptimization (const) for _findPath().

PR-URL: #10789
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information...
mscdex committed Jan 13, 2017
1 parent 28dc848 commit e32425bfcd55497cdad4982908d6fcba9a0e033c
Showing with 5 additions and 4 deletions.
  1. +5 −4 lib/module.js
View
@@ -165,10 +165,11 @@ Module._findPath = function(request, paths, isMain) {
return false;
}
const cacheKey = JSON.stringify({request: request, paths: paths});
if (Module._pathCache[cacheKey]) {
return Module._pathCache[cacheKey];
}
var cacheKey = request + '\x00' +
(paths.length === 1 ? paths[0] : paths.join('\x00'));
var entry = Module._pathCache[cacheKey];
if (entry)
return entry;
var exts;
var trailingSlash = request.length > 0 &&

0 comments on commit e32425b

Please sign in to comment.