-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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(gatsby): cache babel config items #28738
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gatsbot
bot
added
the
status: triage needed
Issue or pull request that need to be triaged and assigned to a reviewer
label
Dec 23, 2020
pieh
added
topic: webpack/babel
Webpack or babel
and removed
status: triage needed
Issue or pull request that need to be triaged and assigned to a reviewer
labels
Dec 23, 2020
pieh
commented
Dec 23, 2020
pieh
commented
Dec 23, 2020
This PR is similar #27974 |
pieh
force-pushed
the
perf/cache-babel-config-items
branch
from
April 1, 2021 10:54
0428d03
to
39efdf3
Compare
3 tasks
pieh
force-pushed
the
perf/cache-babel-config-items
branch
from
April 3, 2021 10:29
39efdf3
to
cede740
Compare
pieh
force-pushed
the
perf/cache-babel-config-items
branch
from
April 6, 2021 12:00
eebbbfa
to
f0bfcd7
Compare
KyleAMathews
approved these changes
Apr 6, 2021
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.
Looks great! Like using webpack as a file watcher. Huge perf improvements 🙌
vladar
approved these changes
Apr 7, 2021
This was referenced Apr 13, 2021
This was referenced Nov 28, 2023
This was referenced Nov 29, 2023
This was referenced Nov 29, 2023
This was referenced Nov 29, 2023
This was referenced Nov 29, 2023
This was referenced Nov 29, 2023
This was referenced Nov 29, 2023
This was referenced Nov 29, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On certain site:
Current:
With this change:
Just the
packages/gatsby/src/utils/babel-loader-helpers.js
change (biggest gain of all the caching added in this PR - at least for site I was benchmarking)There might be more things to cache around this, but this was likely the most heavy thing that will yield biggest benefit
Explanation for changes:
babelLoader.custom(callback)
runs callback function for every input file.babel.createConfigItem
seems to instantiate new plugin/preset every time it's called. This seems to run https://github.com/babel/babel/blob/5b5b548036cde05b424d481c65c1c4a27c6eabc6/packages/babel-preset-env/src/normalize-options.js#L202-L263 separately for every input file even tho our options for@babel/preset-env
don't change for given stage (@babel/preset-env
is just example - it's similar for every babel plugin/preset, just this one seemed to be heaviest on site I was profiling).Because
babel@7
support nested.babelrc
we can't not usebabelLoader.custom
(that would be breaking change/regression), but we can cache/memoize things we know don't change and avoid doing repetitive work.The tricky part would be to memoize the partial config merging internals -
gatsby/packages/gatsby/src/utils/babel-loader-helpers.js
Lines 117 to 139 in 146b197
So instead I opted to memoize one level higher -
gatsby/packages/gatsby/src/utils/babel-loader.js
Lines 64 to 98 in 146b197
Rationale behind this is that number of
.babelrc
files wouldn't be very high and even if we do some repetitive merging for each .babelrc file - at least we won't be doing this for every input file. On the site I was profiling there actually wasn't any extra.babelrc
files and memoizing on that level (on top of memoizingprepareOptions
) yielded extra 5s-10s gains.There is always opportunity to figure out better memoizing setup to support cases of multiple
.babelrc
files better - but it's not clear to me how common using multiple of those configs is (maybe we should track this with telemetry and count "cache misses" per stage)[ch27747]