Skip to content

Commit

Permalink
replace reachableroots with syncAssetsRequired and skip sync deps for…
Browse files Browse the repository at this point in the history
… entries later on
  • Loading branch information
AGawrys committed Apr 11, 2022
1 parent 403ae53 commit d27025e
Showing 1 changed file with 30 additions and 40 deletions.
70 changes: 30 additions & 40 deletions packages/bundlers/experimental/src/ExperimentalBundler.js
Expand Up @@ -291,7 +291,7 @@ function createIdealGraph(

// Attempt to replace reachable roots by building it earlier.
// this models bundleRoots and the assets that require it synchronously
let syncRootsAvailable: ContentGraph<Asset> = new ContentGraph();
let syncRequiredAssets: ContentGraph<Asset> = new ContentGraph();

assetGraph.traverse((node, context, actions) => {
if (node.type !== 'asset') {
Expand Down Expand Up @@ -337,7 +337,7 @@ function createIdealGraph(
dependencyPriorityEdges[dependency.priority],
);
bundleGroupBundleIds.push(nodeId);
syncRootsAvailable.addNodeByContentKeyIfNeeded(asset.id, asset);
syncRequiredAssets.addNodeByContentKeyIfNeeded(asset.id, asset);
assetGraph.traverse((node, _, actions) => {
if (node.value === asset) {
return;
Expand Down Expand Up @@ -366,11 +366,11 @@ function createIdealGraph(
return;
}
//asset node type
let nodeId = syncRootsAvailable.addNodeByContentKeyIfNeeded(
let nodeId = syncRequiredAssets.addNodeByContentKeyIfNeeded(
node.value.id,
node.value,
);
syncRootsAvailable.addEdge(rootNodeId, nodeId);
syncRequiredAssets.addEdge(rootNodeId, nodeId);
}, asset);
}

Expand Down Expand Up @@ -430,24 +430,22 @@ function createIdealGraph(
bundleGraph.getNode(stack[0][1]),
);
invariant(firstBundleGroup !== 'root');
let entry = [...firstBundleGroup.assets][0];
let entrynodeId = syncRootsAvailable.getNodeIdByContentKey(
let entry = [...firstBundleGroup.assets][0]; //this may not be entry
let entrynodeId = syncRequiredAssets.getNodeIdByContentKey(
entry.id,
);
if (entrynodeId !== null) {
let hasThisAssetBySync = false;
syncRootsAvailable
.getNodeIdsConnectedFrom(entrynodeId)
.forEach(nodeId => {
let child = syncRootsAvailable.getNode(nodeId);
if (child?.id === childAsset.id) {
hasThisAssetBySync = true;
}
});
if (hasThisAssetBySync) {
if (
syncRequiredAssets
.getNodeIdsConnectedFrom(entrynodeId)
.some(nodeId => {
let child = syncRequiredAssets.getNode(nodeId);
return child?.id === childAsset.id;
})
) {
//for this dependency mark it internally resolvable for that bundle
let parentBundleId = bundles.has(parentAsset.id)
? bundles.get(parentAsset.id)
? nullthrows(bundles.get(parentAsset.id))
: null;
let parentBundle;
if (parentBundleId !== null) {
Expand All @@ -474,10 +472,7 @@ function createIdealGraph(
bundleId = bundleGraph.addNode(bundle);
bundles.set(childAsset.id, bundleId);
bundleRoots.set(childAsset, [bundleId, bundleId]);
syncRootsAvailable.addNodeByContentKeyIfNeeded(
childAsset.id,
childAsset,
);

bundleGroupBundleIds.push(bundleId);
bundleGraph.addEdge(bundleGraphRootNodeId, bundleId);
} else {
Expand Down Expand Up @@ -579,10 +574,7 @@ function createIdealGraph(

bundles.set(childAsset.id, bundleId);
bundleRoots.set(childAsset, [bundleId, bundleGroupNodeId]);
syncRootsAvailable.addNodeByContentKeyIfNeeded(
childAsset.id,
childAsset,
);

bundleGraph.addEdge(bundleGraphRootNodeId, bundleId);

if (bundleId != bundleGroupNodeId) {
Expand Down Expand Up @@ -612,13 +604,6 @@ function createIdealGraph(
assetReference.get(childAsset).push([dependency, bundle]);
continue;
}
if (dependency.priority === 'sync') {
let nodeId = syncRootsAvailable.addNodeByContentKeyIfNeeded(
childAsset.id,
childAsset,
);
syncRootsAvailable.addEdge(currentRoot, nodeId);
}
}
}
return node;
Expand Down Expand Up @@ -648,9 +633,11 @@ function createIdealGraph(
}

// Models bundleRoots and the assets that require it synchronously
let reachableRoots: ContentGraph<Asset> = new ContentGraph();
for (let [root] of bundleRoots) {
let rootNodeId = reachableRoots.addNodeByContentKeyIfNeeded(root.id, root);
let rootNodeId = syncRequiredAssets.addNodeByContentKeyIfNeeded(
root.id,
root,
);
assetGraph.traverse((node, _, actions) => {
if (node.value === root) {
return;
Expand Down Expand Up @@ -704,12 +691,15 @@ function createIdealGraph(

return;
}
if (entries.has(root)) {
actions.skipChildren();
}
//asset node type
let nodeId = reachableRoots.addNodeByContentKeyIfNeeded(
let nodeId = syncRequiredAssets.addNodeByContentKeyIfNeeded(
node.value.id,
node.value,
);
reachableRoots.addEdge(rootNodeId, nodeId);
syncRequiredAssets.addEdge(rootNodeId, nodeId);
}, root);
}

Expand Down Expand Up @@ -752,11 +742,11 @@ function createIdealGraph(
}
let [siblingBundleRoot] = [...bundleInGroup.assets];
// Assets directly connected to current bundleRoot
let assetsFromBundleRoot = reachableRoots
let assetsFromBundleRoot = syncRequiredAssets
.getNodeIdsConnectedFrom(
reachableRoots.getNodeIdByContentKey(siblingBundleRoot.id),
syncRequiredAssets.getNodeIdByContentKey(siblingBundleRoot.id),
)
.map(id => nullthrows(reachableRoots.getNode(id)));
.map(id => nullthrows(syncRequiredAssets.getNode(id)));

for (let asset of [siblingBundleRoot, ...assetsFromBundleRoot]) {
available.add(asset);
Expand Down Expand Up @@ -793,7 +783,7 @@ function createIdealGraph(
// Unreliable bundleRoot assets which need to pulled in by shared bundles or other means
let reachable: Array<BundleRoot> = getReachableBundleRoots(
asset,
reachableRoots,
syncRequiredAssets,
).reverse();

// Filter out bundles from this asset's reachable array if
Expand Down

0 comments on commit d27025e

Please sign in to comment.