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
perf: lazy load preset-env plugins #13076
perf: lazy load preset-env plugins #13076
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 36de510:
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/44884/ |
e9ef29c
to
36de510
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏃
preset-env
loading on modern targetsThis commit is drafted by a codemod. On modern targets, most plugins in
preset-env
are not actually enabled. However, when Babel is loadingavailable-plugins
, these plugins are still imported. This PR improves loading speed by lazy loading all the available plugins. They are now loaded only whengetPlugin
is called.The cost of resolving many small files and their node_modules is tremendous: In the benchmark case, loading unused plugins costs 663ms. In other words, this PR improving loading
preset-env
from 1.17s to 477ms when compiling against Node.js 15.Benchmark setup:
Create a
babel.config.json
with onlytargets
:Run V8 CPU profiler separately on Babel repo
Load the CPU profile in Chrome DevTools. Check the time of the second LoadFullConfig call
Before:
After: