Skip to content
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

Add configuration option to disable inlined CSS in SSR HTML #2067

Merged
merged 4 commits into from Apr 5, 2024

Conversation

ybnd
Copy link
Member

@ybnd ybnd commented Feb 1, 2023

References

Description

The inlineCriticalCss setting in Angular Universal can pose performance issues.

With this enabled (as it is by default since Angular 13), the server needs to determine which styles are "critical" to a given page. This can take up a good chunk of CPU time.
Turning it off would free up that time, at the expense of loading "smoothness" in the browser.

Previously I thought the decreased "smoothness" outweighed the performance impact, but especially when stacked with the "keepalive fix" the effect is pretty substantial after all.

I've also noticed that while the "flash of unstyled content" is pretty severe in Firefox, it's minimal in Chrome.
Leaving this PR as a draft for now until I can figure out how to mitigate this.

Instructions for Reviewers

Compare this PR's branch with preboot.inlineCriticalCss on/off and see if you notice a significant difference in performance

Checklist

This checklist provides a reminder of what we are going to look for when reviewing your PR. You need not complete this checklist prior to creating your PR (draft PRs are always welcome). If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!

  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes ESLint validation using yarn lint
  • My PR doesn't introduce circular dependencies (verified via yarn check-circ-deps)
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • If my PR includes new libraries/dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR includes new features or configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

When inlining CSS, Angular Universal needs to extract critical styles.
This seems to take up a significant chunk of processing time.

However, loading may appear less smooth when this feature is disabled.

Added to the configuration to make it easier to A/B test this without a full re-build.
@alanorth
Copy link
Contributor

@ybnd I've recently stumbled upon this as well and it seems to be a common observation that inlineCriticalCss isn't optimized for cases where there are many selectors:

After migrating to DSpace 7 recently I have seen very high load from the Node.js main.js processes and I have currently disabled inlineCriticalCss in production. The server is much more stable now, though we also had incredible load coming from bots so it's hard to tell how much was due to this change versus applying strict rate limiting to Amazon, etc network blocks in the nginx reverse proxy.

@tdonohue
Copy link
Member

tdonohue commented Mar 7, 2024

@ybnd and @artlowel : Per today's DevMtg discussion about improvements to SSR performance, it'd be good to revisit this PR and/or officially mark it "ready for review". It sounds like at least one institution (@alanorth 's) has found this useful/beneficial. So, as long as any side effects are minimal, it seems worth considering adding this to 8.0 and (likely also) 7.6.x.

@tdonohue tdonohue added performance / caching Related to performance, caching or embedded objects bug improvement labels Mar 7, 2024
@ybnd ybnd marked this pull request as ready for review March 8, 2024 09:38
Copy link

github-actions bot commented Mar 8, 2024

Hi @ybnd,
Conflicts have been detected against the base branch.
Please resolve these conflicts as soon as you can. Thanks!

@misilot
Copy link
Contributor

misilot commented Mar 12, 2024

I just wanted to add that disabling inlineCriticalCss made DSpace 7 usable in production for us. We were seeing 60+ second page loads. Thank you @alanorth for mentioning this in dspace-tech.

@ybnd
Copy link
Member Author

ybnd commented Mar 12, 2024

Resolved some minor merge conflicts (due to the lint PR).

I've also noticed that while the "flash of unstyled content" is pretty severe in Firefox, it's minimal in Chrome.

Looking back at it now, it doesn't seem that much of a problem honestly. Not sure what changed, but it looks pretty ok now.

@misilot
Copy link
Contributor

misilot commented Mar 12, 2024

Even without this change we were seeing flashing of content

@alanorth
Copy link
Contributor

alanorth commented Mar 12, 2024

Even without this change we were seeing flashing of content

Yes, us too. I use Firefox as my main browser as well. I assumed it was because of the web fonts via @import...

@pnbecker
Copy link
Member

pnbecker commented Mar 20, 2024

We started to use this in production as well and it is very helpful. This must be included in DSpace 8.0 please.

+1

@tdonohue tdonohue added the port to dspace-7_x This PR needs to be ported to `dspace-7_x` branch for next bug-fix release label Mar 20, 2024
@mwoodiupui
Copy link
Member

Should this not be added to config/config.example.yml as well?

@pnbecker
Copy link
Member

pnbecker commented Mar 22, 2024

@mwoodiupui if I see it correctly, this must be set in environment.ts at compile time.

@mwoodiupui
Copy link
Member

Then would someone please point me to the place in the code that prevents overriding this at startup, server-side.

@ybnd
Copy link
Member Author

ybnd commented Mar 22, 2024

@pnbecker @mwoodiupui this should work fine from the YAML config, so probably best to include it in config/config.example.yml indeed

@ybnd
Copy link
Member Author

ybnd commented Mar 22, 2024

@tdonohue @pnbecker @alanorth should we flip the default setting to false, given the overall feedback above?

@tdonohue
Copy link
Member

@ybnd : based on feedback, if setting this to false works better then I'd recommend we make that the default value. That said, we won't merge this until the upgrade to Angular 16 is completed (see #2871 )...so, there's still time for others to test this out as necessary.

Copy link

github-actions bot commented Apr 4, 2024

Hi @ybnd,
Conflicts have been detected against the base branch.
Please resolve these conflicts as soon as you can. Thanks!

@tdonohue
Copy link
Member

tdonohue commented Apr 4, 2024

@ybnd : If you are able to quickly update this, I'd love to get this merged by tomorrow (Friday, April 5). That will let me deploy this on our sandbox.dspace.org site during Testathon which starts next week. Thanks!

@ybnd
Copy link
Member Author

ybnd commented Apr 5, 2024

@tdonohue ready.

@tdonohue tdonohue added this to the 8.0 milestone Apr 5, 2024
@tdonohue tdonohue merged commit d0a8042 into DSpace:main Apr 5, 2024
13 checks passed
@dspace-bot
Copy link

Successfully created backport PR for dspace-7_x:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug high priority improvement performance / caching Related to performance, caching or embedded objects
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

None yet

7 participants