mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
28dc848e70
commit
e32425bfcd
1 changed files with 5 additions and 4 deletions
|
@ -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 &&
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue