Avoid full style recalculation by setting custom property only on element that uses it #597
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addresses #587
This PR is a safer alternative to #592 as it does not change any of the CSS logic, it only sets the custom property at a lower level in the tree.
Since the
--scrolltop
custom property is only used on the#toc
element, we can set its value on that element instead of the root element. This avoids a full style recalculation of all elements on the page which takes very long, and causes massive framerate drops during scrolling.This should not result in any changed behavior or appearance as no other element uses the custom property. It should be a pure optimization with no risk for regressions.
Comparing the performance recordings before and after this change, you can observe the time spent on style recalculation is reduced to a fraction. The long purple chunks shrunk became almost too small to see on the right.
https://colorjs.io/docs/spaces vs https://deploy-preview-597--colorjs.netlify.app/docs/spaces