@@ -106,6 +106,7 @@ const {
106
106
const assert = require ( 'internal/assert' ) ;
107
107
const fs = require ( 'fs' ) ;
108
108
const path = require ( 'path' ) ;
109
+ const { performance } = require ( 'perf_hooks' ) ;
109
110
const { internalModuleStat } = internalBinding ( 'fs' ) ;
110
111
const { safeGetenv } = internalBinding ( 'credentials' ) ;
111
112
const {
@@ -966,10 +967,12 @@ function getExportsForCircularRequire(module) {
966
967
* 3. Otherwise, create a new module for the file and save it to the cache.
967
968
* Then have it load the file contents before returning its exports object.
968
969
* @param {string } request Specifier of module to load via `require`
969
- * @param {string } parent Absolute path of the module importing the child
970
+ * @param {Module } parent Absolute path of the module importing the child
970
971
* @param {boolean } isMain Whether the module is the main entry point
971
972
*/
972
973
Module . _load = function ( request , parent , isMain ) {
974
+ const start = performance . now ( ) ;
975
+
973
976
let relResolveCacheIdentifier ;
974
977
if ( parent ) {
975
978
debug ( 'Module._load REQUEST %s parent: %s' , request , parent . id ) ;
@@ -984,8 +987,14 @@ Module._load = function(request, parent, isMain) {
984
987
if ( cachedModule !== undefined ) {
985
988
updateChildren ( parent , cachedModule , true ) ;
986
989
if ( ! cachedModule . loaded ) {
987
- return getExportsForCircularRequire ( cachedModule ) ;
990
+ const result = getExportsForCircularRequire ( cachedModule ) ;
991
+
992
+ debug ( 'TIMING [%s] [%s]: %d ms' , parent ?. id || '' , request , performance . now ( ) - start ) ;
993
+
994
+ return result ;
988
995
}
996
+
997
+ debug ( 'TIMING [%s] [%s]: %d ms' , parent ?. id || '' , request , performance . now ( ) - start ) ;
989
998
return cachedModule . exports ;
990
999
}
991
1000
delete relativeResolveCache [ relResolveCacheIdentifier ] ;
@@ -1001,6 +1010,8 @@ Module._load = function(request, parent, isMain) {
1001
1010
}
1002
1011
1003
1012
const module = loadBuiltinModule ( id , request ) ;
1013
+
1014
+ debug ( 'TIMING [%s] [%s]: %d ms' , parent ?. id || '' , request , performance . now ( ) - start ) ;
1004
1015
return module . exports ;
1005
1016
}
1006
1017
@@ -1011,16 +1022,24 @@ Module._load = function(request, parent, isMain) {
1011
1022
if ( ! cachedModule . loaded ) {
1012
1023
const parseCachedModule = cjsSourceCache . get ( cachedModule ) ;
1013
1024
if ( ! parseCachedModule || parseCachedModule . loaded ) {
1014
- return getExportsForCircularRequire ( cachedModule ) ;
1025
+ const result = getExportsForCircularRequire ( cachedModule ) ;
1026
+
1027
+ debug ( 'TIMING [%s] [%s]: %d ms' , parent ?. id || '' , request , performance . now ( ) - start ) ;
1028
+
1029
+ return result ;
1015
1030
}
1016
1031
parseCachedModule . loaded = true ;
1017
1032
} else {
1033
+ debug ( 'TIMING [%s] [%s]: %d ms' , parent ?. id || '' , request , performance . now ( ) - start ) ;
1018
1034
return cachedModule . exports ;
1019
1035
}
1020
1036
}
1021
1037
1022
1038
if ( BuiltinModule . canBeRequiredWithoutScheme ( filename ) ) {
1023
1039
const mod = loadBuiltinModule ( filename , request ) ;
1040
+
1041
+ debug ( 'TIMING [%s] [%s]: %d ms' , parent ?. id || '' , request , performance . now ( ) - start ) ;
1042
+
1024
1043
return mod . exports ;
1025
1044
}
1026
1045
@@ -1068,6 +1087,8 @@ Module._load = function(request, parent, isMain) {
1068
1087
}
1069
1088
}
1070
1089
1090
+ debug ( 'TIMING [%s] [%s]: %d ms' , parent ?. id || '' , request , performance . now ( ) - start ) ;
1091
+
1071
1092
return module . exports ;
1072
1093
} ;
1073
1094
0 commit comments