Skip to content

Commit bb5eb93

Browse files
committed
delay rewriting chunks
1 parent 142b90e commit bb5eb93

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/Module.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ class Module extends DependenciesBlock {
8787
this.usedExports = null;
8888
this.providedExports = null;
8989
this.optimizationBailout = [];
90+
91+
// delayed operations
92+
this._rewriteChunkInReasons = undefined;
9093
}
9194

9295
disconnect() {
9396
this.reasons.length = 0;
97+
this._rewriteChunkInReasons = undefined;
9498
this._chunks.clear();
9599

96100
this.id = null;
@@ -196,6 +200,11 @@ class Module extends DependenciesBlock {
196200
}
197201

198202
hasReasonForChunk(chunk) {
203+
if(this._rewriteChunkInReasons) {
204+
for(const operation of this._rewriteChunkInReasons)
205+
this._doRewriteChunkInReasons(operation.oldChunk, operation.newChunks);
206+
this._rewriteChunkInReasons = undefined;
207+
}
199208
for(let i = 0; i < this.reasons.length; i++) {
200209
if(this.reasons[i].hasChunk(chunk))
201210
return true;
@@ -208,6 +217,16 @@ class Module extends DependenciesBlock {
208217
}
209218

210219
rewriteChunkInReasons(oldChunk, newChunks) {
220+
// This is expensive. Delay operation until we really need the data
221+
if(this._rewriteChunkInReasons === undefined)
222+
this._rewriteChunkInReasons = [];
223+
this._rewriteChunkInReasons.push({
224+
oldChunk,
225+
newChunks
226+
});
227+
}
228+
229+
_doRewriteChunkInReasons(oldChunk, newChunks) {
211230
for(let i = 0; i < this.reasons.length; i++) {
212231
this.reasons[i].rewriteChunks(oldChunk, newChunks);
213232
}

0 commit comments

Comments
 (0)