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

reduce cost of style calc+layout in --dialog-scrollgutter #3144

Merged

Conversation

keithamus
Copy link
Member

@keithamus keithamus commented Oct 9, 2024

Authors: Please fill out this form carefully and completely.

Reviewers: By approving this Pull Request you are approving the code change, as well as its deployment and mitigation plans.
Please read this description carefully. If you feel there is anything unclear or missing, please ask for updates.

What are you trying to accomplish?

In our mob pairing session called "Making Dotcom Fast" we ran into an issue where the Primer Dialog component is causing an expensive recalc operation on every page load; this is due to it setting the --dialog-scrollgutter css property, which is a property derived from the innerWidth & body.clientWidth properties.

In order to prevent this cost on page load, we decided to move the operation to the first click event that can be handled by the dialogInvokerButtonHandler. This moves the cost of the recalc away from document load to document click:

image

image

However this change alone still leaves the recalc cost during the first click event which is still costly and could impact INP.

image

So we added some CSS - inspired by this article on the @property rule and how it can lower recalc costs by disabling inheritance - which is perfect for this use case. This reduced recalc cost from ~70-90ms on my machine to under 2ms:

image

We've not moved the code away from the hot-path, and into the click event listener, due to compat risk with the Dialog element and its use in dotcom. This can come at a later date, perhaps.

Screenshots

(See above perf traces)

Integration

List the issues that this change affects.

Risk Assessment

  • Low risk the change is small, highly observable, and easily rolled back.
  • Medium risk changes that are isolated, reduced in scope or could impact few users. The change will not impact library availability.
  • High risk changes are those that could impact customers and SLOs, low or no test coverage, low observability, or slow to rollback.

What approach did you choose and why?

Anything you want to highlight for special attention from reviewers?

Accessibility

  • Fixes axe scan violation - This change fixes an existing axe scan violation.
  • No new axe scan violation - This change does not introduce any new axe scan violations.
  • New axe violation - This change introduces a new axe scan violation. Please describe why the violation cannot be resolved below.

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews (Lookbook)
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

/cc the commit co-authors:
@ansballard, @AdamShwert, @arelia, @arielvalentin, @chrisgavin, @Cbodfield, @composerinteralia, @garman, @dgreif, @erinnachen, @georgebrock, @jibrang, @jfuchs, @khiga8, @manuelpuyol, @mattcosta7, @another-mattr, @MelissaPastore, @theinterned, @phillmv, @Raffo, @cheshire137, @srt32

@keithamus keithamus requested review from a team as code owners October 9, 2024 15:28
@keithamus keithamus requested review from langermank and removed request for a team October 9, 2024 15:28
Copy link

changeset-bot bot commented Oct 9, 2024

🦋 Changeset detected

Latest commit: fa39d1e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/view-components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This comment was marked as off-topic.

Copy link
Contributor

@langermank langermank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool! 😄

keithamus and others added 2 commits October 11, 2024 10:37
Co-authored-by: Aaron Ballard <ansballard@github.com>
Co-authored-by: AdamShwert <adamshwert@github.com>
Co-authored-by: Arelia Jones <2359538+arelia@users.noreply.github.com>
Co-authored-by: Ariel Valentin <arielvalentin@users.noreply.github.com>
Co-authored-by: Chris Gavin <chris@chrisgavin.me>
Co-authored-by: Cody Bodfield <cbodfield@github.com>
Co-authored-by: Daniel Colson <composerinteralia@github.com>
Co-authored-by: Daniel Garman <garman@github.com>
Co-authored-by: Dusty Greif <dgreif@users.noreply.github.com>
Co-authored-by: Erinna Chen <erinnachen@users.noreply.github.com>
Co-authored-by: George Brocklehurst <george@georgebrock.com>
Co-authored-by: Jibran Garcia <jibrang@github.com>
Co-authored-by: Jonathan Fuchs <21195+jfuchs@users.noreply.github.com>
Co-authored-by: Kate Higa <16447748+khiga8@users.noreply.github.com>
Co-authored-by: Manuel Puyol <manuelpuyol@github.com>
Co-authored-by: Matthew Costabile <mattcosta7@github.com>
Co-authored-by: Matthew Reyes <another-mattr@github.com>
Co-authored-by: Melissa Pastore <64283754+MelissaPastore@users.noreply.github.com>
Co-authored-by: Ned Schwartz <theinterned@github.com>
Co-authored-by: Phill MV <phillmv@github.com>
Co-authored-by: Raffaele Di Fazio <raffo@github.com>
Co-authored-by: Sarah Vessels <82317+cheshire137@users.noreply.github.com>
Co-authored-by: Simon Taranto <srt32@users.noreply.github.com>

This comment was marked as off-topic.

@keithamus keithamus enabled auto-merge (squash) October 11, 2024 09:41
@keithamus keithamus merged commit 978e867 into main Oct 11, 2024
34 of 35 checks passed
@keithamus keithamus deleted the reduce-cost-of-style-calc-layout-in-dialog-scrollgutter branch October 11, 2024 09:44
@primer primer bot mentioned this pull request Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants