You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When checking dev tools for the site, I noticed that every scroll event the --scrolltop custom property of the html element is updated.
While at a glance this might not look expensive, it actually results in a style recalculation of all elements on the page. I'm pretty sure it's the only reason the scrolling is choppy, and removing this property update is enough to make the page scroll normally.
Performance recording during scrolling
Details of a single recalc, taking 25.18ms on desktop.
This is triggered by an event listener that only sets a custom property on the root element.
It looks a lot like this CSS can be replaced with position: sticky, completely removing the need to update the root property and thereby removing all the time spent on the purple stuff in above graphs.
The text was updated successfully, but these errors were encountered:
Inwerpsel
changed the title
A full style recalculation is done every scroll on many pages of colorjs.io
An unnecessary full style recalculation is done every scroll on many pages of colorjs.ioAug 25, 2024
Inwerpsel
changed the title
An unnecessary full style recalculation is done every scroll on many pages of colorjs.io
An unnecessary full style recalculation is done every scroll event on many pages of colorjs.ioAug 25, 2024
When checking dev tools for the site, I noticed that every scroll event the
--scrolltop
custom property of thehtml
element is updated.While at a glance this might not look expensive, it actually results in a style recalculation of all elements on the page. I'm pretty sure it's the only reason the scrolling is choppy, and removing this property update is enough to make the page scroll normally.
Performance recording during scrolling
Details of a single recalc, taking 25.18ms on desktop.
This is triggered by an event listener that only sets a custom property on the root element.
color.js/assets/js/index.js
Lines 16 to 18 in f50d95a
The only reference to this custom property is in the
#toc
element, where it's used to move aposition: fixed
element depending on the scroll position.color.js/assets/css/docs.css
Lines 13 to 24 in f50d95a
It looks a lot like this CSS can be replaced with
position: sticky
, completely removing the need to update the root property and thereby removing all the time spent on the purple stuff in above graphs.The text was updated successfully, but these errors were encountered: