inlineCriticalCss is slow
See original GitHub issue🐞 Bug report
What modules are related to this issue?
- aspnetcore-engine
- builders
- common
- express-engine
- hapi-engine
Is this a regression?
No
Description
Recently I tried to enable inlineCriticalCss on our project. And had to roll it back quickly - SSR times jumped sky high.
styles.css
in our project is around 250KB. This includes Angular Material (core + theme) and a number of old-style components that have not been converted to styleUrls
yet. However even if I strip it down to bare minumum - it’s still ~100KB (majority of that are Material styles).
HTML is also somewhat significant - 200KB (after I stripped it off of transfered state), and contain 1500 DOM nodes.
Profiling shows that most of the css inlining time is spent on findOne
call.
My understanding is that critters
has complexity roughly O(N * S)
, where N is number of DOM nodes, and S is number of selectors in the stylesheets. That’s because it queries every selector against the DOM. And our stylesheet (the minimal version) has 1000+ selectors. The regular prod version of the stylesheet - 2600 selectors.
I’m wondering if it could be improved by grouping selectors and discarding a whole group if the top-most selector was not found. E.g if we checked .mat-button
selector and didn’t find any matching node - there is no point in looking for more specific selectors like .mat-button .mat-button-focus-overlay
🔬 Minimal Reproduction
🌍 Your Environment
Angular CLI: 11.2.12
Node: 12.14.1
OS: darwin x64
Angular: 11.2.13
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router
Ivy Workspace: Yes
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1102.12
@angular-devkit/build-angular 0.1102.12
@angular-devkit/core 11.2.12
@angular-devkit/schematics 11.2.12
@angular/cdk 11.2.12
@angular/cli 11.2.12
@angular/material 11.2.12
@nguniversal/builders 11.2.1
@nguniversal/express-engine 11.2.1
@schematics/angular 11.2.12
@schematics/update 0.1102.12
rxjs 6.6.3
typescript 4.1.5
Issue Analytics
- State:
- Created 2 years ago
- Reactions:20
- Comments:28 (5 by maintainers)
Top GitHub Comments
Thank you @alan-agius4 & @ubaidazad. 💯 👍 Temporarily disabling the feature in
server.ts
withinlineCriticalCss: false
worked for us. We await future speed improvements.At FloSports, we have a content-rich web app and several news articles with chunky HTML tables (~150KB) of athlete/team data (imagine an Excel dumps worth). Those articles really magnified the speed issue with +20s renders. In addition to these articles, in general, we saw an increase in SSR latency of 2.1x to 3.2x across all of our pages.
We didn’t notice the issue until it deployed to production. Below you can see when we were alerted via Datadog of an anomaly and debugged a bit before manually rolling back the deployment.
You need to disable it in your
server.ts
.https://github.com/angular/angular/issues/42098#issuecomment-841629552