@@ -359,7 +359,19 @@ function setModuleParent(value) {
359
359
moduleParentCache . set ( this , value ) ;
360
360
}
361
361
362
- let debug = require ( 'internal/util/debuglog' ) . debuglog ( 'module' , ( fn ) => {
362
+ const { debuglog, isDebugEnabled } = require ( 'internal/util/debuglog' ) ;
363
+
364
+ let debug = debuglog ( 'module' , ( fn ) => {
365
+ debug = fn ;
366
+ } ) ;
367
+
368
+ let hrtimeBigIntTimingFn = ( ) => {
369
+ hrtimeBigIntTimingFn = isDebugEnabled ( 'timing_module_cjs' ) ? process . hrtime . bigint : ( ) => 0
370
+
371
+ return hrtimeBigIntTimingFn ( )
372
+ } ;
373
+
374
+ let debugTiming = debuglog ( 'timing_module_cjs' , ( fn ) => {
363
375
debug = fn ;
364
376
} ) ;
365
377
@@ -958,6 +970,10 @@ function getExportsForCircularRequire(module) {
958
970
return module . exports ;
959
971
}
960
972
973
+ function logTiming ( request , parent , start ) {
974
+ debugTiming ( '[%s] [%s]: %d ms' , parent ?. id || '' , request , Number ( ( hrtimeBigIntTimingFn ( ) - start ) ) / 1e6 ) ;
975
+ }
976
+
961
977
/**
962
978
* Load a module from cache if it exists, otherwise create a new module instance.
963
979
* 1. If a module already exists in the cache: return its exports object.
@@ -966,10 +982,12 @@ function getExportsForCircularRequire(module) {
966
982
* 3. Otherwise, create a new module for the file and save it to the cache.
967
983
* Then have it load the file contents before returning its exports object.
968
984
* @param {string } request Specifier of module to load via `require`
969
- * @param {string } parent Absolute path of the module importing the child
985
+ * @param {Module } parent Absolute path of the module importing the child
970
986
* @param {boolean } isMain Whether the module is the main entry point
971
987
*/
972
988
Module . _load = function ( request , parent , isMain ) {
989
+ const start = hrtimeBigIntTimingFn ( ) ;
990
+
973
991
let relResolveCacheIdentifier ;
974
992
if ( parent ) {
975
993
debug ( 'Module._load REQUEST %s parent: %s' , request , parent . id ) ;
@@ -984,8 +1002,14 @@ Module._load = function(request, parent, isMain) {
984
1002
if ( cachedModule !== undefined ) {
985
1003
updateChildren ( parent , cachedModule , true ) ;
986
1004
if ( ! cachedModule . loaded ) {
987
- return getExportsForCircularRequire ( cachedModule ) ;
1005
+ const result = getExportsForCircularRequire ( cachedModule ) ;
1006
+
1007
+ logTiming ( request , parent , start ) ;
1008
+
1009
+ return result ;
988
1010
}
1011
+
1012
+ logTiming ( request , parent , start ) ;
989
1013
return cachedModule . exports ;
990
1014
}
991
1015
delete relativeResolveCache [ relResolveCacheIdentifier ] ;
@@ -1001,6 +1025,8 @@ Module._load = function(request, parent, isMain) {
1001
1025
}
1002
1026
1003
1027
const module = loadBuiltinModule ( id , request ) ;
1028
+
1029
+ logTiming ( request , parent , start ) ;
1004
1030
return module . exports ;
1005
1031
}
1006
1032
@@ -1011,16 +1037,24 @@ Module._load = function(request, parent, isMain) {
1011
1037
if ( ! cachedModule . loaded ) {
1012
1038
const parseCachedModule = cjsSourceCache . get ( cachedModule ) ;
1013
1039
if ( ! parseCachedModule || parseCachedModule . loaded ) {
1014
- return getExportsForCircularRequire ( cachedModule ) ;
1040
+ const result = getExportsForCircularRequire ( cachedModule ) ;
1041
+
1042
+ logTiming ( request , parent , start ) ;
1043
+
1044
+ return result ;
1015
1045
}
1016
1046
parseCachedModule . loaded = true ;
1017
1047
} else {
1048
+ logTiming ( request , parent , start ) ;
1018
1049
return cachedModule . exports ;
1019
1050
}
1020
1051
}
1021
1052
1022
1053
if ( BuiltinModule . canBeRequiredWithoutScheme ( filename ) ) {
1023
1054
const mod = loadBuiltinModule ( filename , request ) ;
1055
+
1056
+ logTiming ( request , parent , start ) ;
1057
+
1024
1058
return mod . exports ;
1025
1059
}
1026
1060
@@ -1068,6 +1102,8 @@ Module._load = function(request, parent, isMain) {
1068
1102
}
1069
1103
}
1070
1104
1105
+ logTiming ( request , parent , start ) ;
1106
+
1071
1107
return module . exports ;
1072
1108
} ;
1073
1109
0 commit comments