@@ -78,7 +78,7 @@ const {
78
78
createFakeHook
79
79
} = require ( "./util/deprecation" ) ;
80
80
const processAsyncTree = require ( "./util/processAsyncTree" ) ;
81
- const { getRuntimeKey, RuntimeSpecMap } = require ( "./util/runtime" ) ;
81
+ const { getRuntimeKey } = require ( "./util/runtime" ) ;
82
82
const { isSourceEqual } = require ( "./util/source" ) ;
83
83
84
84
/** @template T @typedef {import("tapable").AsArray<T>} AsArray<T> */
@@ -2178,7 +2178,39 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2178
2178
let statNew = 0 ;
2179
2179
let statChanged = 0 ;
2180
2180
let statUnchanged = 0 ;
2181
+ let statReferencesChanged = 0 ;
2181
2182
let statWithoutHash = 0 ;
2183
+
2184
+ const computeReferences = module => {
2185
+ /** @type {WeakMap<Dependency, Module> } */
2186
+ let references = undefined ;
2187
+ for ( const connection of moduleGraph . getOutgoingConnections ( module ) ) {
2188
+ const d = connection . dependency ;
2189
+ const m = connection . module ;
2190
+ if ( ! d || ! m || unsafeCacheDependencies . has ( d ) ) continue ;
2191
+ if ( references === undefined ) references = new WeakMap ( ) ;
2192
+ references . set ( d , m ) ;
2193
+ }
2194
+ return references ;
2195
+ } ;
2196
+
2197
+ /**
2198
+ * @param {Module } module the module
2199
+ * @param {WeakMap<Dependency, Module> } references references
2200
+ * @returns {boolean } true, when the references differ
2201
+ */
2202
+ const compareReferences = ( module , references ) => {
2203
+ if ( references === undefined ) return true ;
2204
+ for ( const connection of moduleGraph . getOutgoingConnections ( module ) ) {
2205
+ const d = connection . dependency ;
2206
+ if ( ! d ) continue ;
2207
+ const entry = references . get ( d ) ;
2208
+ if ( entry === undefined ) continue ;
2209
+ if ( entry !== connection . module ) return false ;
2210
+ }
2211
+ return true ;
2212
+ } ;
2213
+
2182
2214
for ( const module of modules ) {
2183
2215
const hash = module . buildInfo && module . buildInfo . hash ;
2184
2216
if ( typeof hash === "string" ) {
@@ -2188,27 +2220,33 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2188
2220
const memCache = new WeakTupleMap ( ) ;
2189
2221
moduleMemCacheCache . set ( module , {
2190
2222
hash : hash ,
2223
+ references : computeReferences ( module ) ,
2191
2224
memCache
2192
2225
} ) ;
2193
2226
moduleMemCaches . set ( module , memCache ) ;
2194
2227
affectedModules . add ( module ) ;
2195
2228
statNew ++ ;
2196
- } else if ( cachedMemCache . hash === hash ) {
2197
- // keep the old mem cache
2198
- moduleMemCaches . set ( module , cachedMemCache . memCache ) ;
2199
- statUnchanged ++ ;
2200
- } else {
2229
+ } else if ( cachedMemCache . hash !== hash ) {
2201
2230
// use a new one
2202
2231
const memCache = new WeakTupleMap ( ) ;
2203
- moduleMemCacheCache . set ( module , {
2204
- hash : hash ,
2205
- memCache
2206
- } ) ;
2207
2232
moduleMemCaches . set ( module , memCache ) ;
2208
2233
affectedModules . add ( module ) ;
2209
2234
cachedMemCache . hash = hash ;
2235
+ cachedMemCache . references = computeReferences ( module ) ;
2210
2236
cachedMemCache . memCache = memCache ;
2211
2237
statChanged ++ ;
2238
+ } else if ( ! compareReferences ( module , cachedMemCache . references ) ) {
2239
+ // use a new one
2240
+ const memCache = new WeakTupleMap ( ) ;
2241
+ moduleMemCaches . set ( module , memCache ) ;
2242
+ affectedModules . add ( module ) ;
2243
+ cachedMemCache . references = computeReferences ( module ) ;
2244
+ cachedMemCache . memCache = memCache ;
2245
+ statReferencesChanged ++ ;
2246
+ } else {
2247
+ // keep the old mem cache
2248
+ moduleMemCaches . set ( module , cachedMemCache . memCache ) ;
2249
+ statUnchanged ++ ;
2212
2250
}
2213
2251
} else {
2214
2252
infectedModules . add ( module ) ;
@@ -2261,7 +2299,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2261
2299
affectedModules . add ( referencingModule ) ;
2262
2300
}
2263
2301
const memCache = new WeakTupleMap ( ) ;
2264
- const cache = moduleMemCacheCache . get ( module ) ;
2302
+ const cache = moduleMemCacheCache . get ( referencingModule ) ;
2265
2303
cache . memCache = memCache ;
2266
2304
moduleMemCaches . set ( referencingModule , memCache ) ;
2267
2305
}
@@ -2275,7 +2313,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2275
2313
infectedModules . size
2276
2314
} infected of ${
2277
2315
this . modules . size
2278
- } ) modules flagged as affected (${ statNew } new modules, ${ statChanged } changed, ${ statUnchanged } unchanged, ${ statWithoutHash } without hash)`
2316
+ } ) modules flagged as affected (${ statNew } new modules, ${ statChanged } changed, ${ statReferencesChanged } references changed, ${ statUnchanged } unchanged, ${ statWithoutHash } without hash)`
2279
2317
) ;
2280
2318
}
2281
2319
@@ -3095,16 +3133,11 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3095
3133
// modules with async blocks depend on the chunk graph and can't be cached that way
3096
3134
module . blocks . length === 0 &&
3097
3135
moduleMemCaches . get ( module ) ;
3098
- /** @type {RuntimeSpecMap<Set<string>> } */
3099
- const moduleRuntimeRequirementsMemCache =
3100
- memCache &&
3101
- memCache . provide (
3102
- "moduleRuntimeRequirements" ,
3103
- ( ) => new RuntimeSpecMap ( )
3104
- ) ;
3105
3136
for ( const runtime of chunkGraph . getModuleRuntimes ( module ) ) {
3106
- if ( moduleRuntimeRequirementsMemCache ) {
3107
- const cached = moduleRuntimeRequirementsMemCache . get ( runtime ) ;
3137
+ if ( memCache ) {
3138
+ const cached = memCache . get (
3139
+ `moduleRuntimeRequirements-${ getRuntimeKey ( runtime ) } `
3140
+ ) ;
3108
3141
if ( cached !== undefined ) {
3109
3142
if ( cached !== null ) {
3110
3143
chunkGraph . addModuleRuntimeRequirements (
@@ -3125,8 +3158,11 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3125
3158
} else if ( additionalModuleRuntimeRequirements . isUsed ( ) ) {
3126
3159
set = new Set ( ) ;
3127
3160
} else {
3128
- if ( moduleRuntimeRequirementsMemCache ) {
3129
- moduleRuntimeRequirementsMemCache . set ( runtime , null ) ;
3161
+ if ( memCache ) {
3162
+ memCache . set (
3163
+ `moduleRuntimeRequirements-${ getRuntimeKey ( runtime ) } ` ,
3164
+ null
3165
+ ) ;
3130
3166
}
3131
3167
continue ;
3132
3168
}
@@ -3137,12 +3173,18 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3137
3173
if ( hook !== undefined ) hook . call ( module , set , context ) ;
3138
3174
}
3139
3175
if ( set . size === 0 ) {
3140
- if ( moduleRuntimeRequirementsMemCache ) {
3141
- moduleRuntimeRequirementsMemCache . set ( runtime , null ) ;
3176
+ if ( memCache ) {
3177
+ memCache . set (
3178
+ `moduleRuntimeRequirements-${ getRuntimeKey ( runtime ) } ` ,
3179
+ null
3180
+ ) ;
3142
3181
}
3143
3182
} else {
3144
- if ( moduleRuntimeRequirementsMemCache ) {
3145
- moduleRuntimeRequirementsMemCache . set ( runtime , set ) ;
3183
+ if ( memCache ) {
3184
+ memCache . set (
3185
+ `moduleRuntimeRequirements-${ getRuntimeKey ( runtime ) } ` ,
3186
+ set
3187
+ ) ;
3146
3188
chunkGraph . addModuleRuntimeRequirements (
3147
3189
module ,
3148
3190
runtime ,
@@ -3555,13 +3597,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3555
3597
// modules with async blocks depend on the chunk graph and can't be cached that way
3556
3598
module . blocks . length === 0 &&
3557
3599
moduleMemCaches . get ( module ) ;
3558
- /** @type {RuntimeSpecMap<string> } */
3559
- const moduleHashesMemCache =
3560
- memCache &&
3561
- memCache . provide ( "moduleHashes" , ( ) => new RuntimeSpecMap ( ) ) ;
3562
3600
for ( const runtime of chunkGraph . getModuleRuntimes ( module ) ) {
3563
- if ( moduleHashesMemCache ) {
3564
- const digest = moduleHashesMemCache . get ( runtime ) ;
3601
+ if ( memCache ) {
3602
+ const digest = memCache . get ( `moduleHash- ${ getRuntimeKey ( runtime ) } ` ) ;
3565
3603
if ( digest !== undefined ) {
3566
3604
chunkGraph . setModuleHashes (
3567
3605
module ,
@@ -3583,8 +3621,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3583
3621
hashDigest ,
3584
3622
hashDigestLength
3585
3623
) ;
3586
- if ( moduleHashesMemCache ) {
3587
- moduleHashesMemCache . set ( runtime , digest ) ;
3624
+ if ( memCache ) {
3625
+ memCache . set ( `moduleHash- ${ getRuntimeKey ( runtime ) } ` , digest ) ;
3588
3626
}
3589
3627
}
3590
3628
}
0 commit comments