Repository: parcel-bundler/parcel
File: packages/bundlers/default/src/DefaultBundler.js (JavaScript)

Code before:
  }
  // Step Merge Share Bundles: Merge any shared bundles under the minimum bundle size back into
  // their source bundles, and remove the bundle.
  // We should include "bundle reuse" as shared bundles that may be removed but the bundle itself would have to be retained
  for (let [bundleNodeId, bundle] of bundleGraph.nodes) {
    if (bundle === 'root') continue;
    if (
      bundle.sourceBundles.size > 0 &&
      bundle.mainEntryAsset == null &&
      bundle.size < config.minBundleSize
    ) {
      removeBundle(bundleGraph, bundleNodeId, assetReference);
    }
  }

  let modifiedSourceBundles = new Set();
  // Step Remove Shared Bundles: Remove shared bundles from bundle groups that hit the parallel request limit.
  for (let bundleGroupId of bundleGraph.getNodeIdsConnectedFrom(rootNodeId)) {
    // Find shared bundles in this bundle group.
    let bundleId = bundleGroupId;

    // We should include "bundle reuse" as shared bundles that may be removed but the bundle itself would have to be retained
    let bundleIdsInGroup = getBundlesForBundleGroup(bundleId); //get all bundlegrups this bundle is an ancestor of

    // Filter out inline assests as they should not contribute to PRL
    let numBundlesContributingToPLR = bundleIdsInGroup.reduce((count, b) => {
      let bundle = nullthrows(bundleGraph.getNode(b));
      return count + (bundle === 'root' || bundle.bundleBehavior !== 'inline');
    }, 0);

    if (numBundlesContributingToPLR > config.maxParallelRequests) {
      let sharedBundleIdsInBundleGroup = bundleIdsInGroup.filter(b => {
        let bundle = nullthrows(bundleGraph.getNode(b));
        // shared bundles must have source bundles, we could have a bundle
        // connected to another bundle that isnt a shared bundle, so check
        return (
          bundle !== 'root' && bundle.sourceBundles.size > 0 && bundleId != b
        );
      });

      // Sort the bundles so the smallest ones are removed first.
      let sharedBundlesInGroup = sharedBundleIdsInBundleGroup
        .map(id => ({
          id,
          bundle: nullthrows(bundleGraph.getNode(id)),
        }))
        .map(({id, bundle}) => {
          // For Flow
          invariant(bundle !== 'root');
          return {id, bundle};
        })

Review comment (suggestion):
I would just modify bundleIdsInGroup instead of using a new variable. (Unless we using bundleIdsInGroup somewhere else where you haven't replaced it with `numBundlesContributingToPLR` )

Code after:
  }
  // Step Merge Share Bundles: Merge any shared bundles under the minimum bundle size back into
  // their source bundles, and remove the bundle.
  // We should include "bundle reuse" as shared bundles that may be removed but the bundle itself would have to be retained
  for (let [bundleNodeId, bundle] of bundleGraph.nodes) {
    if (bundle === 'root') continue;
    if (
      bundle.sourceBundles.size > 0 &&
      bundle.mainEntryAsset == null &&
      bundle.size < config.minBundleSize
    ) {
      removeBundle(bundleGraph, bundleNodeId, assetReference);
    }
  }

  let modifiedSourceBundles = new Set();

  // Step Remove Shared Bundles: Remove shared bundles from bundle groups that hit the parallel request limit.
  for (let bundleGroupId of bundleGraph.getNodeIdsConnectedFrom(rootNodeId)) {
    // Find shared bundles in this bundle group.
    let bundleId = bundleGroupId;

    // We should include "bundle reuse" as shared bundles that may be removed but the bundle itself would have to be retained
    let bundleIdsInGroup = getBundlesForBundleGroup(bundleId); //get all bundlegrups this bundle is an ancestor of

    // Filter out inline assests as they should not contribute to PRL
    let numBundlesContributingToPRL = bundleIdsInGroup.reduce((count, b) => {
      let bundle = nullthrows(bundleGraph.getNode(b));
      invariant(bundle !== 'root');
      return count + (bundle.bundleBehavior !== 'inline');
    }, 0);

    if (numBundlesContributingToPRL > config.maxParallelRequests) {
      let sharedBundleIdsInBundleGroup = bundleIdsInGroup.filter(b => {
        let bundle = nullthrows(bundleGraph.getNode(b));
        // shared bundles must have source bundles, we could have a bundle
        // connected to another bundle that isnt a shared bundle, so check
        return (
          bundle !== 'root' && bundle.sourceBundles.size > 0 && bundleId != b
        );
      });

      // Sort the bundles so the smallest ones are removed first.
      let sharedBundlesInGroup = sharedBundleIdsInBundleGroup
        .map(id => ({
          id,
          bundle: nullthrows(bundleGraph.getNode(id)),
        }))
        .map(({id, bundle}) => {
          // For Flow
          invariant(bundle !== 'root');