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 integration #8180

Merged
merged 113 commits into from Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from 91 commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
3860eca
internalization bug
gorakong Feb 9, 2022
406cacb
Cleanup
Feb 9, 2022
c69e6d2
Always add assets to reachable bundles
lettertwo Feb 9, 2022
a5b5ed5
Merge branch 'v2' of github.com:parcel-bundler/parcel into internaliz…
gorakong Feb 9, 2022
51ab20f
cleanup
gorakong Feb 9, 2022
febecde
fixed test regressions
gorakong Feb 10, 2022
c403cda
add ref edges whenever there are bundle edges
gorakong Feb 10, 2022
8ac0701
add edge from bundlegroups to bundles wip
gorakong Feb 15, 2022
a474413
* Get inline bundles in bundle group in HTML packager
thebriando Feb 15, 2022
0a9f32d
use and follow reference edges again
gorakong Feb 16, 2022
73ad828
set env whenever we create bundles
gorakong Feb 17, 2022
eb3703b
Check to add parallel edges from all paths to an asset from a bundle
Feb 19, 2022
463bed0
Always register referenced bundles before pruning when building bundl…
Feb 22, 2022
d775731
Merge remote-tracking branch 'origin/v2' into internalization-bug
Feb 22, 2022
dbfab75
Revert "set env whenever we create bundles"
Feb 23, 2022
757eff8
Add test for referenced roots in bundle manifest
Feb 23, 2022
6e22065
Add reused sibling bundles to asyncBundleRootGraph
Feb 28, 2022
f347cac
Add test case for asset that has both an async and sync import
thebriando Mar 1, 2022
a4162b2
ExperimentalBundler: stop at isolated bundles
Mar 1, 2022
2a02631
ExperimentalBundler: fix step 7 comment
Mar 1, 2022
0d20d02
ExperimentalBundler: initialize entry bundles with no ancestors
Mar 1, 2022
22ba3bb
ExperimentalBundler: accept shared bundles extracted from workers
Mar 1, 2022
df5a741
Remove unused async bundles if needed
Mar 2, 2022
d03348d
Merge remote-tracking branch 'origin/v2' into more-experimental-bundl…
Mar 2, 2022
731c07b
Scope-hositing with new bundler: allow less duplication
Mar 2, 2022
345e0cc
Uncomment line in getSymbolResolution
thebriando Mar 3, 2022
727dde7
Consider sibling availability before removing from ancestorAssets
Mar 3, 2022
2032542
Uncomment line in getSymbolResolution
thebriando Mar 3, 2022
37e5c6a
Upgrade flow to 0.173.0 (#7809)
Mar 8, 2022
ae3ee14
Remove reachableBundles
thebriando Mar 9, 2022
7a98f04
Bump lmdb (#7797)
mischnic Mar 9, 2022
968fde6
Replace typeof before DCE (#7788)
mischnic Mar 9, 2022
8136500
Consider sibling availability before removing from ancestorAssets
Mar 3, 2022
a5d9610
Consider assets in siblings before duplicating
Mar 3, 2022
fd4e7db
Merge remote-tracking branch 'github/v2' into more-experimental-bundl…
Mar 10, 2022
a7946d9
Remove unrelated change
Mar 10, 2022
eab212a
Don't consider any of parent's async bundles as sibling
Mar 14, 2022
07cb7fc
Merge branch 'v2' into more-experimental-bundler-fixes
thebriando Mar 16, 2022
0cbd1f3
Remove unused structure
Mar 16, 2022
8feaea7
Merge branch 'more-experimental-bundler-fixes' of https://github.com/…
AGawrys Mar 17, 2022
81ffca5
remove eager bundle reuse and related lending code
AGawrys Mar 22, 2022
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
b971d75
Alter tests with mode production and correct assets with logic for sp…
AGawrys Mar 29, 2022
f887d71
Merge branch 'v2' into more-experimental-bundler-fixes
Mar 29, 2022
01dd511
Skip unused dependencies in experimental bundler
devongovett Mar 29, 2022
d9049a1
Implement getBundleFromBundleRoot
Mar 29, 2022
76214cb
Only add dependencies to CSS module JS, not CSS
devongovett Mar 26, 2022
7d20342
Handle multiple assets on dependencies in reachability
Mar 30, 2022
5107bd5
ScopeHoistingPackager: Handle different wrapped ancestries in wrappin…
Mar 31, 2022
403ae53
move reachable root creation earlier to prevent unnecessary async bundle
AGawrys Apr 5, 2022
4e04010
Merge branch 'v2' of github.com:parcel-bundler/parcel into parallel-r…
gorakong Apr 5, 2022
7478eae
Merge remote-tracking branch 'origin/v2' into more-experimental-bundl…
thebriando Apr 6, 2022
d27025e
replace reachableroots with syncAssetsRequired and skip sync deps for…
AGawrys Apr 11, 2022
91170c3
Revert "replace reachableroots with syncAssetsRequired and skip sync …
AGawrys Apr 26, 2022
364f081
Revert "move reachable root creation earlier to prevent unnecessary a…
AGawrys Apr 26, 2022
fb426b1
Implement cleanup for internalized deps from entrys
AGawrys Apr 26, 2022
30de01d
flow and clean up and comments
AGawrys Apr 27, 2022
239bb91
forgot to add the test files
AGawrys Apr 27, 2022
137801c
skip assets for reachable if isolated or inline fix invariant
AGawrys Apr 27, 2022
31e58d9
merge in v2
AGawrys Apr 27, 2022
e87347d
skip assets for reachable if isolated or inline fix invariant
AGawrys Apr 27, 2022
c09957e
Merge branch 'v2' of github.com:parcel-bundler/parcel into parallel-r…
gorakong Apr 28, 2022
e5c4c8a
Use bundleGroup instead of bundle root for determining needsStableName
Apr 29, 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
955fb67
Filter out bundleroots from reacable if they are subgraphs, consider …
AGawrys May 4, 2022
fe4efb4
Add bundle.mainEntryAsset
Apr 29, 2022
95b8588
ExperimentalBundler: merge bundleBehavior and needsStableName
May 3, 2022
e289ef5
Merge branch 'v2' into parallel-request-limit
May 4, 2022
7a4a0f4
Merge remote-tracking branch 'origin/wbinnssmith/multiple-bundles-sam…
AGawrys May 4, 2022
7934257
Merge remote-tracking branch 'origin/parallel-request-limit' into exp…
AGawrys May 4, 2022
59f4ef4
don't remove bundles depended on by url
AGawrys May 4, 2022
c36daf0
don't flatted bundle to bundlegroup edges
AGawrys May 4, 2022
c7a80fa
point config to default bundler, crete type change bundle regardless …
AGawrys May 10, 2022
183e9e7
extract shared bundles from inline bundles
AGawrys May 11, 2022
7ee8435
Internalize all async bundle before placing assets into bundles, add …
AGawrys May 12, 2022
ec2ec0a
add assert bundles to test
AGawrys May 13, 2022
335e31e
Reverse merge asset insertion order to maintain dep order for css, re…
AGawrys May 13, 2022
f7a2296
Forked tests which rely on size calculation for shared bundles which …
AGawrys May 23, 2022
770bc1f
Addedge support to toposort, use edges to differentiate parallel and …
AGawrys May 24, 2022
82c6d43
Alter test description
AGawrys May 24, 2022
bd26b85
Merge in v2
AGawrys May 24, 2022
58dfd51
remove numbered steps & remove parallel request limit since subject t…
AGawrys May 24, 2022
0226dc4
Add support for multiple targets by bundling per entries per target
AGawrys Jun 1, 2022
0c3a653
clean up
AGawrys Jun 1, 2022
f851eb7
parallel request limits + test
gorakong Jun 2, 2022
36c647c
Merge branch 'experimental-bundler-integration' of https://github.com…
gorakong Jun 2, 2022
de2085a
add test and assert on number of bundles instead
gorakong Jun 2, 2022
d43c3b6
add test and assert on number of bundles instead
gorakong Jun 2, 2022
1ed5a4e
Merge branch 'experimental-bundler-integration' of https://github.com…
gorakong Jun 2, 2022
361bda0
Fix
mischnic Jun 2, 2022
9445ca0
clean up logic and naming
AGawrys Jun 9, 2022
3c18f9c
typo
AGawrys Jun 10, 2022
4718cae
Merge remote-tracking branch 'origin/v2' into experimental-bundler-in…
AGawrys Jun 14, 2022
c635729
parallel request limit wip
gorakong Jun 16, 2022
4bbad88
Dont allow multiple bundles of entry type in entry bundlegroups
AGawrys Jun 21, 2022
0caa81b
Merge remote-tracking branch 'origin/v2' into experimental-bundler-in…
AGawrys Jun 21, 2022
b415d1e
fix
gorakong Jun 21, 2022
a2a87c1
Comments
AGawrys Jun 24, 2022
d3d11b5
Merge branch 'experimental-bundler-integration' of https://github.com…
gorakong Jun 24, 2022
3323602
fixed bugs in parallel request limit implementation & update related …
gorakong Jun 24, 2022
81b9da3
Merge branch 'v2' of https://github.com/parcel-bundler/parcel into ex…
gorakong Jun 24, 2022
15085a2
flow
AGawrys Jun 24, 2022
10f09e9
Fork diagnostic bundler config test to say correct bundler
AGawrys Jun 27, 2022
fc9e55b
typos
AGawrys Jun 27, 2022
7e74049
flow reverse
AGawrys Jun 27, 2022
2df0724
Add parallel step for running integration tests with experimental bun…
thebriando Jun 29, 2022
1662eb7
Merge branch 'v2' into experimental-bundler-integration
AGawrys Jun 29, 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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -27,7 +27,7 @@ yarn install
yarn build-native
```

If you want, you can create a temporary example for debugging in the folder `packages/examples`. You can start by copying the `simple` example and try to reproduce the bug. It has everything set up for working on local changes and you can run `yarn build` to build the project. If you're re-using another example or creating one from scratch, make sure to use the `--no-cache` flag for `parcel build` to see your local changes reflected. *Please don't commit this example.*
If you want, you can create a temporary example for debugging in the folder `packages/examples`. You can start by copying the `simple` example and try to reproduce the bug. It has everything set up for working on local changes and you can run `yarn build` to build the project. If you're re-using another example or creating one from scratch, make sure to use the `--no-cache` flag for `parcel build` to see your local changes reflected. _Please don't commit this example._

After you've figured out where the issue originated from and found a fix, try to add a test case or ask for help on how to proceed if the use case is more complex.

Expand Down
102 changes: 102 additions & 0 deletions contributorDocs/Bundler.md
@@ -0,0 +1,102 @@
# Bundler.md

## Experimental Bundler Contributing Docs

From here on I will refer to the Experimental Bundler simply as "The Bundler", and the Default Bundler as "Old Bundler" or "Previous Bundler".

The Bundler works by creating an ideal graph which models bundles, connected to other bundles by what references it, and thus models BundleGroups. This graph is called the BundleGraph.

In additon to the BundleGraph, we build up structures to inform the decoration of the old BundleGraph. We will go over these structures as we go through the algorithm.

First, we enter `bundle({bundleGraph, config})`. Here, "bundleGraph" is actually just the assetGraph turned into a type `MutableBundleGraph`, which will then be mutated in decorate, and turned into what we expect the bundleGraph to be as per the old (default) bundler structure & what the rest of Parcel expects a BundleGraph to be.

`bundle({bundleGraph, config})` First gets a Mapping of target to entries, In most cases there is only one target, and one or more entries. (Targets are pertinent in monorepos or projects where you will have two or more distDirs, or output folders.) Then calls create IdealGraph and Decorate per target.

IdealGraphCreation has a few loops over the assetGraph (MutableBundleGraph)

## Bundle Creation

Create Bundles for entries, then traverse the AssetGraph (aka MutableBundleGraph) and create bundles for async inports, type changes, and add edges for those bundles.

## Merging of Types

Merge Bundles that belong to the same exact bundleGroups, of the same type, unless dependency specifies not to.

## Determine Reachability

To determine what assets go where, without unnecessart duplication and an ideal amount of shared bundles, we first built two strcutures,
one traversal each. `ReachableRoots` to store `sync` relationships, and `ancestorAssets` to store the minimal availability through `parallel` and `async` relationships.

We Build AncestorAssets with a peek ahead strategy. We visit nodes from the bundleRootGraph that have been topologically sorted. At a BundleRoot, we access it's available assets (via ancestorAssets), and add to that all assets within the bundles in that BundleGroup. This set is available to all bundles in a particular bundleGroup because bundleGroups are just bundles loaded at the same time. However it is not true that a bundle's available assets = all assets of all the bundleGroups it belongs to. It's the intesection of those sets.

Now that we have bundleGroup availability, we will propogate that down to all the children of this bundleGroup. For a child, we also must maintain parallel availability. If it has parrallel siblings that come before it, those, too, are available to it. Add those parrallel available assets to the set of available assets for this child as well.

Most of the time, a child will have many parent bundleGroups, so the next time we peek at a child from another parent, we will intersect the availability built there with the previously computed availability. this ensures no matter which bundleGroup loads a partular bundle, it will only assume availability of assets it has under any circumstance.

**ReachableRoots** is a Graph of Asset Nodes which represents a BundleRoot, to all assets (non-bundleroot assets) available to it synchornously (directly) built by traversing the assetgraph once.

**AncestorAssets** is a Map that tracks a bundleRoot, to all assets available to it (meaning they will exist gurenteed when the bundleRoot is loaded)

This map is built up by a topological sorting of the bundleRootGraph (technically just the asset graph minus sync deps). The topological sort ensures all parents are visited before the node we want to process.

TODO: replace these strcutures with one graph with many edge types.

## Internalize Async Bundles

Next, internalize Async bundles if and only if, the bundle is synchronously available elsewhere. (Does this mean parallel bundles could also be internalized ?). We can query sync assests available via reachableRoots. If the parent has the bundleRoot by reachableRoots AND ancestorAssets, internalize it.

## Insert non BundleRoot Assets or create shared bundles

Now, we take assets, and reduce what is reachable from them. Filter out entries, since they can't have shared bundles. Neither can non-splittable, isolated, or needing of stable name bundles. Reserve those bundles since we add the asset back into them.

The remaining reachable bundleRoots, are then filtered by if the asset is not in their ancestry (meaning its actually not reachable from the bundleRoot).

Finally, filter out bundleRoots (bundles) from this assets reachable if they are subgraphs, **and** reuse that subgraph bundle by drawing an edge. Essentially, if two bundles within an assets reachable array, have an ancestor-subgraph relationship, draw that edge.

## Merge sharedBundles

Go through the sharedBundles and delete any that hit the limits

# Structure Definitions

**BundleGraph**: A Graph of Bundles and a root node (dummy string), which models only Bundles, and connections to their referenceing Bundle

**ReferencingBundle**: The Bundle that first brings in another bundle (essentially the FIRST parent of a bundle, this may or may not be a bundleGroup)

**BundleGroup**: A Bundle that marks the start of a group of bundles which must be loaded together. There are no actual BundleGroup nodes, just bundles that take on that role.

**BundleRoot**: An asset that is the main entry of a Bundle.

**BundleRootGraph**: A ContentGraph which models BundleRoots (aka Assets), and only the relationships between them (async or parallel). This (along with reachable roots) informs reachability.

**ReachableRoots**: A ContentGraph which models BundleRoots and what is reachable from them, including non-bundleRoot assets as well as other BundleRoots.

**AncestorAssets**: A mapping of BundleRoots to ALL assets reachable from it (This means all the assets reachable from it's ancestors (sync, async, parallel), PLUS any sync assets available to itself via bundlegroup or self, PLUS any parallel siblings that are guarenteed to load before it)

# Other Definitions, as they relate to the bundler

**Isolated** : An isolated Dependency, or Bundle must contain all assets it needs to load.

**URL Specifier Type** : Cannot be merged or internalized.

## Test Changes (Remove this section before PR)
AGawrys marked this conversation as resolved.
Show resolved Hide resolved

Some test case additions/ changes.

`async dependency can be resolved internally and externally from two different bundles` -> essentially tests that when we internalize an async bundle, we only delete when needed (i.e. do not delete if something else needs it)

`should reuse a bundle when its main asset (aka bundleroot) is imported sychronously` -> renamed because this DOES NOT test that a shared bundle is created, but rather, a bundle is reused instead of a shared bundle. (related to the side-effecty reachable filter)

### Forked Tests

`supports dynamic import and url to the same specifier in the same file` AND `supports dynamic import and url to the same specifier in the same file with scope hoisting` are forked for bundles because we default a bundle's bundlebehavior to the one with the more limitations and just use that insted of two.

`supports reexporting an asset from a shared bundle inside a shared bundle` -> forked due to size calculation. Default bundler includes the size of source bundles instead of just the assets to be shared in size calculation.

Cache tests for `bundler config` altered in order to test bundles changing based on config.

TODO:

- check if bundlegraph & bundleroot graph may be merged
- add (more) comments to explain what code is doing
- add diagrams to contributor docs and format