-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime"); | |
* @property {boolean | undefined} minAvailableModulesOwned true, if minAvailableModules is owned and can be modified | ||
* @property {ModuleSetPlus[]} availableModulesToBeMerged enqueued updates to the minimal set of available modules | ||
* @property {Set<Module>=} skippedItems modules that were skipped because module is already available in parent chunks (need to reconsider when minAvailableModules is shrinking) | ||
* @property {Set<[Module, ConnectionState]>=} skippedModuleConnections referenced modules that where skipped because they were not active in this runtime | ||
* @property {Set<[Module, ModuleGraphConnection[]]>=} skippedModuleConnections referenced modules that where skipped because they were not active in this runtime | ||
* @property {ModuleSetPlus | undefined} resultingAvailableModules set of modules available including modules from this chunk group | ||
* @property {Set<ChunkGroupInfo> | undefined} children set of children chunk groups, that will be revisited when availableModules shrink | ||
* @property {Set<ChunkGroupInfo> | undefined} availableSources set of chunk groups that are the source for minAvailableModules | ||
|
@@ -73,6 +73,25 @@ const bySetSize = (a, b) => { | |
return b.size + b.plus.size - a.size - a.plus.size; | ||
}; | ||
|
||
/** | ||
* @param {ModuleGraphConnection[]} connections list of connections | ||
* @param {RuntimeSpec} runtime for which runtime | ||
* @returns {ConnectionState} connection state | ||
*/ | ||
const getActiveStateOfConnections = (connections, runtime) => { | ||
let merged = connections[0].getActiveState(runtime); | ||
if (merged === true) return true; | ||
for (let i = 1; i < connections.length; i++) { | ||
const c = connections[i]; | ||
merged = ModuleGraphConnection.addConnectionStates( | ||
merged, | ||
c.getActiveState(runtime) | ||
); | ||
if (merged === true) return true; | ||
} | ||
return merged; | ||
}; | ||
|
||
const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => { | ||
let blockCache; | ||
let modules; | ||
|
@@ -99,9 +118,6 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => { | |
if (!m) continue; | ||
// We skip weak connections | ||
if (connection.weak) continue; | ||
const state = connection.getActiveState(runtime); | ||
// We skip inactive connections | ||
if (state === false) continue; | ||
|
||
const block = moduleGraph.getParentBlock(d); | ||
let index = moduleGraph.getParentBlockIndex(d); | ||
|
@@ -115,48 +131,55 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => { | |
modules = blockModulesMap.get((blockCache = block)); | ||
} | ||
|
||
const i = index << 2; | ||
const i = index * 3; | ||
modules[i] = m; | ||
modules[i + 1] = state; | ||
modules[i + 1] = connection.getActiveState(runtime); | ||
modules[i + 2] = connection; | ||
} | ||
|
||
for (const modules of arrays) { | ||
if (modules.length === 0) continue; | ||
let indexMap; | ||
let length = 0; | ||
outer: for (let j = 0; j < modules.length; j += 2) { | ||
outer: for (let j = 0; j < modules.length; j += 3) { | ||
const m = modules[j]; | ||
if (m === undefined) continue; | ||
const state = modules[j + 1]; | ||
const connection = modules[j + 2]; | ||
if (indexMap === undefined) { | ||
let i = 0; | ||
for (; i < length; i += 2) { | ||
for (; i < length; i += 3) { | ||
if (modules[i] === m) { | ||
const merged = modules[i + 1]; | ||
modules[i + 2].push(connection); | ||
if (merged === true) continue outer; | ||
modules[i + 1] = ModuleGraphConnection.addConnectionStates( | ||
merged, | ||
state | ||
); | ||
continue outer; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jdehaan
|
||
} | ||
} | ||
modules[length] = m; | ||
length++; | ||
modules[length] = state; | ||
length++; | ||
modules[length] = [connection]; | ||
length++; | ||
if (length > 30) { | ||
// To avoid worse case performance, we will use an index map for | ||
// linear cost access, which allows to maintain O(n) complexity | ||
// while keeping allocations down to a minimum | ||
indexMap = new Map(); | ||
for (let i = 0; i < length; i += 2) { | ||
for (let i = 0; i < length; i += 3) { | ||
indexMap.set(modules[i], i + 1); | ||
} | ||
} | ||
} else { | ||
const idx = indexMap.get(m); | ||
if (idx !== undefined) { | ||
const merged = modules[idx]; | ||
modules[idx + 1].push(connection); | ||
if (merged === true) continue outer; | ||
modules[idx] = ModuleGraphConnection.addConnectionStates( | ||
merged, | ||
|
@@ -168,6 +191,8 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => { | |
modules[length] = state; | ||
indexMap.set(m, length); | ||
length++; | ||
modules[length] = [connection]; | ||
length++; | ||
} | ||
} | ||
} | ||
|
@@ -207,7 +232,7 @@ const visitModules = ( | |
* | ||
* @param {DependenciesBlock} block block | ||
* @param {RuntimeSpec} runtime runtime | ||
* @returns {(Module | ConnectionState)[]} block modules in flatten tuples | ||
* @returns {(Module | ConnectionState | ModuleGraphConnection[])[]} block modules in flatten tuples | ||
*/ | ||
const getBlockModules = (block, runtime) => { | ||
if (blockModulesMapRuntime !== runtime) { | ||
|
@@ -382,7 +407,7 @@ const visitModules = ( | |
/** @type {QueueItem[]} */ | ||
let queueDelayed = []; | ||
|
||
/** @type {[Module, ConnectionState][]} */ | ||
/** @type {[Module, ModuleGraphConnection[]][]} */ | ||
const skipConnectionBuffer = []; | ||
/** @type {Module[]} */ | ||
const skipBuffer = []; | ||
|
@@ -582,7 +607,7 @@ const visitModules = ( | |
const { minAvailableModules } = chunkGroupInfo; | ||
// Buffer items because order need to be reversed to get indices correct | ||
// Traverse all referenced modules | ||
for (let i = 0; i < blockModules.length; i += 2) { | ||
for (let i = 0; i < blockModules.length; i += 3) { | ||
const refModule = /** @type {Module} */ (blockModules[i]); | ||
if (chunkGraph.isModuleInChunk(refModule, chunk)) { | ||
// skip early if already connected | ||
|
@@ -592,7 +617,11 @@ const visitModules = ( | |
blockModules[i + 1] | ||
); | ||
if (activeState !== true) { | ||
skipConnectionBuffer.push([refModule, activeState]); | ||
const connections = /** @type {ModuleGraphConnection[]} */ ( | ||
blockModules[i + 2] | ||
); | ||
skipConnectionBuffer.push([refModule, connections]); | ||
// We skip inactive connections | ||
if (activeState === false) continue; | ||
} | ||
if ( | ||
|
@@ -666,7 +695,7 @@ const visitModules = ( | |
|
||
if (blockModules !== undefined) { | ||
// Traverse all referenced modules | ||
for (let i = 0; i < blockModules.length; i += 2) { | ||
for (let i = 0; i < blockModules.length; i += 3) { | ||
const refModule = /** @type {Module} */ (blockModules[i]); | ||
const activeState = /** @type {ConnectionState} */ ( | ||
blockModules[i + 1] | ||
|
@@ -1172,7 +1201,11 @@ const visitModules = ( | |
/** @type {ModuleSetPlus} */ | ||
(info.minAvailableModules); | ||
for (const entry of info.skippedModuleConnections) { | ||
const [module, activeState] = entry; | ||
const [module, connections] = entry; | ||
const activeState = getActiveStateOfConnections( | ||
connections, | ||
info.runtime | ||
); | ||
if (activeState === false) continue; | ||
if (activeState === true) { | ||
info.skippedModuleConnections.delete(entry); | ||
|
@@ -1286,7 +1319,7 @@ const visitModules = ( | |
return; | ||
} | ||
|
||
for (let i = 0; i < blockModules.length; i += 2) { | ||
for (let i = 0; i < blockModules.length; i += 3) { | ||
const refModule = /** @type {Module} */ (blockModules[i]); | ||
const activeState = /** @type {ConnectionState} */ ( | ||
blockModules[i + 1] | ||
|
Why this change of control flow?
Is this possibly causing (#18119 (comment)) some chunks to be omitted from the federation entry file? Unfortunately I have no clue what exactly is happening here, but formally this is a control flow change not aligned with the other changes which are purely injecting an additional 3rd info on the stack.