-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Inline the PostCSS config file into the webpack config #45030
Conversation
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
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.
Small change, big win, thank you! Code looks good to me.
This is one of the times I wish we had implemented this.
client/webpack.config.js
Outdated
plugins: () => | ||
[ | ||
autoprefixerPlugin(), | ||
browserslistEnv === 'defaults' && | ||
postcssCustomPropertiesPlugin( { | ||
importFrom: [ calypsoColorSchemes ], | ||
} ), | ||
].filter( Boolean ), |
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.
Is there a reason to making plugins a function instead of a plain array? I might be mistaken but PostCSS API seems to accept an array.
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.
Not really, it can be a plain array just fine 🙂 All the variables that are used to compute the plugin list are global constants. Fixed in f42a554
…el dependencies They were specified only in `calypso-build/package.json` until now, which is not entirely correct. The packages are used a lot outside the `calypso-build` context.
Allows for more powerful configuration of the PostCSS pipeline, e.g., inlining the config completely instead of loading it from file.
…config.js The config file doesn't need to be loaded 800+ times for every .scss compilation. It's created only once when loading the webpack config.
8afbb60
to
f42a554
Compare
For completeness, I don't get the performance benefits in my system: the fallback build tooks about 2 minutes in all cases:
|
@scinos I see that when testing with "cold caches", you use the following command to delete the caches: On my machine, I also have a Is it expected that the |
Let me rerun the tests with deleting |
Data with a colder cache:
The diff is ~7 seconds. Not sure if it is statistically relevant, given that I got runs with a difference of >20 seconds. |
Thanks for testing! The 7 seconds diff is not that great, but still nice if it proves to be real. The patch removes a code path that loads a small JS file from filesystem and executes it, repeated 800 times. 7 seconds looks like a plausible timing for that. |
This is a follow up to @alshakero's
postcss-custom-properties
optimization in #42829.Here I'm trying to speed up the webpack build by inlining the PostCSS config file into the webpack config. The
postcss-loader
doesn't need to load the config file 800+ times, for each*.scss
compilation, but it's created only once, as an in-memory object, when creating the webpack config.I needed to add a new option,
postCssOptions
, to thecalypso-build/webpack/sass
loader, enhancing the existingpostCssConfig
option. The existing option only lets us specify a path and context for the config file, but the new options lets up specify theplugins
directly, skipping the config-file-loading step completely.This speeds up mainly the
fallback
production build, the only one that usespostcss-custom-properties
plugin. Testing locally, the timings improved from 167 seconds before to 94 seconds after (yarn run build-client-fallback
with production env variables, skipping the linting check).I'm not sure if these timings improvements are for real -- maybe the
cache-loader
and other similar things skew the result? It's worth trying to reproduce the results by the reviewer.How to test:
Verify that the fallback build output still contains fallback definitions for CSS theme colors, and that the
autoprefixer
did its work, too.