Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Safeguards to prevent layout trashing for window dimensions #6092

Merged
merged 7 commits into from
May 25, 2021

Conversation

germain-gg
Copy link
Contributor

Accessing mundane things like window.innerWidth can have a devastating impact on performance. This pull request tries to alleviate this to end this once and for all by caching the window dimensions in a newly created UIStore and forcing everyone to use it over the native browser primitives (thanks to ESLint).

This pull request also cleans up a few old event listeners that were not needed during resize as well as only scheduling work if it needs to happen

Overall there is a net decrease of the frame rendering time, with less JavaScript being executed for every frame allowing the application to hit slightly higher FPS

Before 🐌

Screen Shot 2021-05-25 at 10 36 18

After 🐎

Screen Shot 2021-05-25 at 10 34 20

It is better to access the device orientation using media queries as it will not force a reflow compared to accessing innerWidth/innerHeight
This helper should hold data related to the UI and access save in a smart to avoid performance pitfalls in other parts of the application
@germain-gg germain-gg requested a review from a team May 25, 2021 09:40
Copy link
Member

@t3chguy t3chguy left a comment

Choose a reason for hiding this comment

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

Looks sane otherwise
bit worried the removal of some of the resizeNotifier might have some corner case effects but should be minimal if any. Perf impact looks nice

src/stores/UIStore.ts Outdated Show resolved Hide resolved
@germain-gg germain-gg merged commit 1751b4b into develop May 25, 2021
@germain-gg germain-gg deleted the gsouquet/window-dimensions-reflow branch May 25, 2021 11:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants