Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experimental Bundler]: Implement parallel request limits #7863

Closed
wants to merge 28 commits into from
Closed
Changes from 13 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1c30b0a
implement parallel request limits
gorakong Mar 24, 2022
f8a8e65
cleanup
gorakong Mar 24, 2022
a6f3065
Merge branch 'v2' of github.com:parcel-bundler/parcel into parallel-r…
gorakong Mar 28, 2022
892edd3
create all shared bundles first then remove later
gorakong Mar 29, 2022
4e04010
Merge branch 'v2' of github.com:parcel-bundler/parcel into parallel-r…
gorakong Apr 5, 2022
c09957e
Merge branch 'v2' of github.com:parcel-bundler/parcel into parallel-r…
gorakong Apr 28, 2022
7faa3d7
remove asset references for deleted bundles + minor fixes
gorakong May 2, 2022
5f734f6
Merge branch 'v2' of github.com:parcel-bundler/parcel into parallel-r…
gorakong May 3, 2022
1ca53e0
Merge branch 'v2' into parallel-request-limit
gorakong May 3, 2022
8091e67
Merge branch 'v2' into parallel-request-limit
gorakong May 3, 2022
e289ef5
Merge branch 'v2' into parallel-request-limit
May 4, 2022
4e22979
Merge branch 'v2' into parallel-request-limit
gorakong May 6, 2022
7fe7cac
Merge branch 'v2' into parallel-request-limit
gorakong May 9, 2022
ca162b2
Merge branch 'v2' into parallel-request-limit
May 16, 2022
b8060e9
revise method of getting shared bundles from bundlegroup + integratio…
gorakong Jun 2, 2022
e251bec
Merge branch 'v2' into parallel-request-limit
gorakong Jun 2, 2022
45c6b09
deep equal
gorakong Jun 2, 2022
209dc21
Merge branch 'v2' of https://github.com/parcel-bundler/parcel into pa…
gorakong Jun 15, 2022
c5eab76
fix bugs with missing node/edges
gorakong Jun 24, 2022
c17c539
Merge branch 'v2' into parallel-request-limit
gorakong Jun 24, 2022
8d942fc
remove logs
gorakong Jun 24, 2022
7b6c959
Merge branch 'parallel-request-limit' of https://github.com/parcel-bu…
gorakong Jun 24, 2022
466e51b
change config to default in validateSchema
gorakong Jun 27, 2022
df9a74f
Merge branch 'v2' of https://github.com/parcel-bundler/parcel into pa…
gorakong Jun 27, 2022
2bc4c1c
Merge branch 'v2' of https://github.com/parcel-bundler/parcel into pa…
gorakong Jul 5, 2022
8abca30
include all referenced bundles in bundleGroups
gorakong Jul 5, 2022
fdbe58e
update bundle.sourceBundle when removing shared bundle
gorakong Jul 5, 2022
a2e15fc
match limit to num shared bundles in group
gorakong Jul 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
78 changes: 71 additions & 7 deletions packages/bundlers/experimental/src/ExperimentalBundler.js
Expand Up @@ -878,7 +878,64 @@ function createIdealGraph(
if (bundle === 'root') continue;
if (bundle.sourceBundles.length > 0 && bundle.size < config.minBundleSize) {
sharedToSourceBundleIds.delete(bundleNodeId);
removeBundle(bundleGraph, bundleNodeId);
removeBundle(bundleGraph, bundleNodeId, assetReference);
}
}

// Step 8: Remove shared bundles from bundle groups that hit the parallel request limit.
for (let [bundleId, bundleGroupId] of bundleRoots.values()) {
// Only handle bundle group entries.
if (bundleId != bundleGroupId) {
continue;
}

// Find the bundles in this bundle group.
let bundleIdsInGroup = bundleGraph.getNodeIdsConnectedFrom(bundleGroupId);
if (bundleIdsInGroup.length > config.maxParallelRequests) {
// Sort the bundles so the smallest ones are removed first.
let bundlesInGroup = bundleIdsInGroup
.map(id => nullthrows(bundleGraph.getNode(id)))
.map(bundle => {
// For Flow
invariant(bundle !== 'root');
return bundle;
})
.sort((a, b) => a.size - b.size);

// Remove bundles until the bundle group is within the parallel request limit.
for (
let i = 0;
i < bundlesInGroup.length - config.maxParallelRequests;
i++
) {
let bundleId = bundleIdsInGroup[i];
let bundle = nullthrows(bundleGraph.getNode(bundleId));
invariant(bundle !== 'root');
// Add all assets in the shared bundle into the source bundles that are within this bundle group.
let sourceBundles = bundle.sourceBundles
.filter(b => bundlesInGroup.includes(b))
.map(id => nullthrows(bundleGraph.getNode(id)));

for (let sourceBundle of sourceBundles) {
invariant(sourceBundle !== 'root');
for (let asset of bundle.assets) {
sourceBundle.assets.add(asset);
sourceBundle.size += asset.stats.size;
}
}

// Remove the edge from this bundle group to the shared bundle.
bundleGraph.removeEdge(bundleGroupId, bundleId);
// If there is now only a single bundle group that contains this bundle,
// merge it into the remaining source bundles. If it is orphaned entirely, remove it.
let incomingNodeCount =
bundleGraph.getNodeIdsConnectedTo(bundleId).length;
if (incomingNodeCount === 1) {
removeBundle(bundleGraph, bundleId, assetReference);
} else if (incomingNodeCount === 0) {
bundleGraph.removeNode(bundleId);
}
}
}
}

Expand Down Expand Up @@ -950,11 +1007,18 @@ function createBundle(opts: {|
};
}

function removeBundle(bundleGraph: Graph<Bundle | 'root'>, bundleId: NodeId) {
function removeBundle(
bundleGraph: Graph<Bundle | 'root'>,
bundleId: NodeId,
assetReference: DefaultMap<Asset, Array<[Dependency, Bundle]>>,
) {
let bundle = nullthrows(bundleGraph.getNode(bundleId));
invariant(bundle !== 'root');

for (let asset of bundle.assets) {
assetReference.set(
asset,
assetReference.get(asset).filter(t => !t.includes(bundle)),
);
for (let sourceBundleId of bundle.sourceBundles) {
let sourceBundle = nullthrows(bundleGraph.getNode(sourceBundleId));
invariant(sourceBundle !== 'root');
Expand All @@ -971,7 +1035,7 @@ async function loadBundlerConfig(
options: PluginOptions,
): Promise<ResolvedBundlerConfig> {
let conf = await config.getConfig<BundlerConfig>([], {
packageKey: '@parcel/bundler-default',
packageKey: '@parcel/bundler-experimental',
gorakong marked this conversation as resolved.
Show resolved Hide resolved
});
if (!conf) {
return HTTP_OPTIONS['2'];
Expand All @@ -985,10 +1049,10 @@ async function loadBundlerConfig(
data: conf?.contents,
source: await options.inputFS.readFile(conf.filePath, 'utf8'),
filePath: conf.filePath,
prependKey: `/${encodeJSONKeyComponent('@parcel/bundler-default')}`,
prependKey: `/${encodeJSONKeyComponent('@parcel/bundler-experimental')}`,
},
'@parcel/bundler-default',
'Invalid config for @parcel/bundler-default',
'@parcel/bundler-experimental',
'Invalid config for @parcel/bundler-experimental',
);

let http = conf.contents.http ?? 2;
Expand Down