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

Add bundle builds #6194

Draft
wants to merge 11 commits into
base: v2
Choose a base branch
from
Draft

Add bundle builds #6194

wants to merge 11 commits into from

Conversation

aminya
Copy link
Contributor

@aminya aminya commented Apr 27, 2021

↪️ Pull Request

  • This PR tries to add bundle builds for Parcel to speed up loading time. The plan is to provide a parcel-bundle binary that uses the bundled builds instead of the source files. This is the second take on Bundle CSSNano optimizer (make Parcel 2-5 s faster) #5671, but without modifying the default behavior of the packages (with parcel binary).

  • It's always a very good test to use a tool on itself. Bundling Parcel using Parcel can reveal many bugs, and also result in improving the Parcel code itself.

💻 Examples

🚨 Test instructions

✔️ PR Todo

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs
@height
Copy link

height bot commented Apr 27, 2021

Link Height tasks by mentioning a task ID in the pull request title or description, commit messages, or comments.

💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.

"bundle": {
"context": "node",
"includeNodeModules": {
"@parcel/core": false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed because of require.resolve('./worker')

Comment on lines +54 to +55
"@parcel/fs": false,
"@parcel/package-manager": false,
Copy link
Contributor Author

@aminya aminya Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creates a cryptic error when the bundle is used.

Error: Name already registered with serializer
    at registerSerializableClass (C:\parcel\packages\core\core\lib\serializer.js:43:11)
    at Object.<anonymous> (C:\parcel\packages\core\fs\lib\NodeFS.js:229:39)
    at Module.n._compile (C:\parcel\packages\core\parcel\lib\bin.bundle.js:64:1076211)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at o (C:\parcel\packages\core\parcel\lib\bin.bundle.js:64:1075905)
    at Object.<anonymous> (C:\parcel\packages\core\fs\lib\index.js:21:15)
    at Module.n._compile (C:\parcel\packages\core\parcel\lib\bin.bundle.js:64:1076211)
 ERROR  Command failed with exit code 1.
"@parcel/core": false,
"@parcel/fs": false,
"@parcel/package-manager": false,
"@parcel/fs-search": false
Copy link
Contributor Author

@aminya aminya Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prebuild relies on the location of the file.

@@ -38,5 +42,20 @@
},
"devDependencies": {
"@parcel/babel-register": "2.0.0-beta.2"
},
"scripts": {
"bundle": "cross-env NODE_ENV=production parcel build --target bundle lib/bin.js --no-scope-hoist"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scope hoisting results in this error when the bundle is used:

TypeError: Class extends value #<Object> is not a constructor or null
    at $e0ff572d13646e06f40e076cefd6686f$exec (C:\parcel\packages\core\parcel\lib\bin.bundle.js:25:1424680)
    at $e0ff572d13646e06f40e076cefd6686f$init (C:\parcel\packages\core\parcel\lib\bin.bundle.js:25:1443053)
    at $ee4cb4f5c2d240a4c58df653433665f4$var$_commander (C:\parcel\packages\core\parcel\lib\bin.bundle.js:25:1447963)
    at Object.<anonymous> (C:\parcel\packages\core\parcel\lib\bin.bundle.js:25:1454346)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47
@@ -54,8 +54,7 @@
"@parcel/fs": false,
"@parcel/package-manager": false,
"@parcel/fs-search": false,
"highlight.js": false,
"node-forge": false
Copy link
Contributor Author

@aminya aminya Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node-forge makes the bundle very large. Although not all of its exports are used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a pull request to fix this issue: #6198

@@ -54,8 +54,7 @@
"@parcel/fs": false,
"@parcel/package-manager": false,
"@parcel/fs-search": false,
"highlight.js": false,
Copy link
Contributor Author

@aminya aminya Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

highlight-js makes the bundle very large. Although many of its required languages are not used.

Copy link
Contributor Author

@aminya aminya Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a pull request to fix this issue
#6196

@mischnic
Copy link
Member

Is this significantly faster for you? Because all of the plugins as specified in the parcelrc are still unbundled

@aminya
Copy link
Contributor Author

aminya commented Apr 28, 2021

Is this significantly faster for you? Because all of the plugins as specified in the parcelrc are still unbundled

This isn't ready yet. It's just the start. Also, the improvements shouldn't be measured only based on build time. As I mentioned in the OP, it's always a very good test to use a tool on itself. Bundling Parcel using Parcel can reveal many bugs, and also result in improving the Parcel code itself.

So far I have extracted these two pull requests from this pull request which are helpful even for the default Parcel binary.
#6196
#6198

@mischnic
Copy link
Member

As I mentioned in the OP, it's always a very good test to use a tool on itself. Bundling Parcel using Parcel can reveal many bugs, and also result in improving the Parcel code itself.

This isn't the first effort to do that: https://parcel2-repl.vercel.app

@aminya
Copy link
Contributor Author

aminya commented Apr 28, 2021

Thanks. In addition to the benefits I mentioned before, these changes (like the fixes I have done in the other two PRs) will reduce the payload size significantly.

I am anticipating that the main build-time performance benefits start to show themselves when we bundle the plugins such as cssnano. I already showed this in #5671. Just bundling CSSNano reduced the build time by 2-5 seconds. This is a "constant overhead" that anyone who uses CSS will pay! By the new parcel-bundle binary, these overheads are removed (for those who optionally use it).

I am going to take a look at the source code of the REPL to see which parts I can borrow for parcel-bundle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants