summaryrefslogtreecommitdiff
path: root/lib/module.js
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2017-01-13 05:19:54 -0500
committerBrian White <mscdex@mscdex.net>2017-03-10 23:48:53 -0500
commite32425bfcd55497cdad4982908d6fcba9a0e033c (patch)
tree3530faca7b935ca57e62e2d02e15bf4504566e34 /lib/module.js
parent28dc848e702b70f8c07941a1dfd46227f90c8267 (diff)
downloadandroid-node-v8-e32425bfcd55497cdad4982908d6fcba9a0e033c.tar.gz
android-node-v8-e32425bfcd55497cdad4982908d6fcba9a0e033c.tar.bz2
android-node-v8-e32425bfcd55497cdad4982908d6fcba9a0e033c.zip
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>
Diffstat (limited to 'lib/module.js')
-rw-r--r--lib/module.js9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/module.js b/lib/module.js
index 1b9c2413b7..77675fcd98 100644
--- a/lib/module.js
+++ b/lib/module.js
@@ -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 &&