-
Notifications
You must be signed in to change notification settings - Fork 8.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
[optimizer][scss] Webpack bundles/repeats potentially unnecessary code with each file #102829
Comments
Pinging @elastic/kibana-operations (Team:Operations) |
This |
In our case, since all of the SCSS files are imported by a single SCSS file, that import only happens once, so all of the vars and mixins are imported. I'm not seeing the dedupe or removal of unused SCSS in the local dev build. Perhaps that's handled in the prod build? I guess we'll see when the PR finishes, but that would be awesome. I wish there was a way to get prod webpack profiles of your plugin locally, easily... I'm always afraid I'm chasing a red herring. |
Best I can tell the scss behind this
Use |
@spalger I updated the issue with the results from the PR: less 21k and 63 fewer modules. |
I did a local All of the portions to the right are different builds of the individual SCSS files, with supporting code. |
Pinging @elastic/kibana-core (Team:Core) |
Pinging @elastic/kibana-design (Team:Kibana-Design) |
I am also tagging Core and Design on this issue. Let me know if this is incorrect. The I am not sure if there is anything we can do here, other than creating documentation to suggest plugins don't liberally import SCSS into their components and instead limit the total count of imports. |
Okay, I've dug into the bundles and while your assertion that there is extra overhead caused by using separate CSS imports is correct your assignment of blame to the To make things worse every CSS module is actually in the bundle 4 times, one for each theme, so we end up with a lot of overhead caused by the style-loader mechanism. Looking at this code it's really very small, but the fact that we're including v7 light and dark themes in the distributable is definitely compounding this error. I'd like to look into #102930 to see if we can mitigate this overhead a little rather than recommend that teams unify their CSS. We also don't want all CSS in one download so that it's always downloaded and applied, but breaking the CSS up a ton causes a lot of overhead, especially if your CSS is small. |
Thanks for the info, @spalger ... I updated the description of the issue to reflect this. |
I haven't tested, but maybe we can gain some improvements with https://github.com/webpack-contrib/style-loader#singletonstyletag ? Another idea: is there an equivalent of |
I am curious if this is the same issue I noticed or if I should create a separate issue? In bundle analyzer I noticed:
Should at least those loaders be a part of |
@Dosant We could probably move the runtimes into externals, though I'm not 100% sure they're compatible (I think I tried this but found an issue which indicated it's not possible) but I do think it's a separate issue. This is more about the overhead created to call the runtime with unique options for each CSS/SCSS module. |
Unassigning Core as this seems only related to our bundling system |
Today, the optimizerEvery compiled SCSS file is bloated with an additional ~3k of codewebpack.config
prepends SCSS files with mixins, variables and other pre-requisites a SCSS file might utilize. As a result, ewhether it needs it or notin order for webpack to append the CSS as a style element to the DOM. This is compounded by the number of themes we support. The impact of this is better described in #102822 but in raw, locally-generated builds, combining six small SCSS file imports into a singleindex.scss
file had a *9% reduction in bundle size:(Before on left, after on right)
I was chatting about this with @tylersmalley, and it appears the only preventative measure we have to prevent the duplication of this code is for plugins to combine their SCSS imports into a single SCSS file. Since Canvas (and Kibana) is starting to move to CSS-in-JS, this might be an acceptable short-to-medium-term solution.
EDIT: The results from #102822 are in:
Moving 8 imports to the
index.scss
file reduced the bundle size by 21k and removed 63 modules.The text was updated successfully, but these errors were encountered: