From bfd2f03f1b6cfc9ea1fc3262c747d85b3f23cec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Louren=C3=A7o?= Date: Mon, 25 Mar 2024 22:15:29 -0300 Subject: [PATCH] module: print amount of load time of a module --- lib/internal/modules/cjs/loader.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 22e77d8bff70c09..a0c97af9a9481ad 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -970,6 +970,8 @@ function getExportsForCircularRequire(module) { * @param {boolean} isMain Whether the module is the main entry point */ Module._load = function(request, parent, isMain) { + const start = performance.now(); + let relResolveCacheIdentifier; if (parent) { debug('Module._load REQUEST %s parent: %s', request, parent.id); @@ -984,8 +986,14 @@ Module._load = function(request, parent, isMain) { if (cachedModule !== undefined) { updateChildren(parent, cachedModule, true); if (!cachedModule.loaded) { - return getExportsForCircularRequire(cachedModule); + const result = getExportsForCircularRequire(cachedModule); + + debug(`TIMING [%s]: %d ms`, request, performance.now() - start); + + return result; } + + debug(`TIMING [%s]: %d ms`, request, performance.now() - start); return cachedModule.exports; } delete relativeResolveCache[relResolveCacheIdentifier]; @@ -1001,6 +1009,8 @@ Module._load = function(request, parent, isMain) { } const module = loadBuiltinModule(id, request); + + debug(`TIMING [%s]: %d ms`, request, performance.now() - start); return module.exports; } @@ -1011,16 +1021,24 @@ Module._load = function(request, parent, isMain) { if (!cachedModule.loaded) { const parseCachedModule = cjsSourceCache.get(cachedModule); if (!parseCachedModule || parseCachedModule.loaded) { - return getExportsForCircularRequire(cachedModule); + const result = getExportsForCircularRequire(cachedModule); + + debug(`TIMING [%s]: %d ms`, request, performance.now() - start); + + return result; } parseCachedModule.loaded = true; } else { + debug(`TIMING [%s]: %d ms`, request, performance.now() - start); return cachedModule.exports; } } if (BuiltinModule.canBeRequiredWithoutScheme(filename)) { const mod = loadBuiltinModule(filename, request); + + debug(`TIMING [%s]: %d ms`, request, performance.now() - start); + return mod.exports; } @@ -1068,6 +1086,8 @@ Module._load = function(request, parent, isMain) { } } + debug(`TIMING [%s]: %d ms`, request, performance.now() - start); + return module.exports; };