Marking and measuring style computation, layout calculations, etc
Nobody has claimed this yet.
- Dominant language
- Bikeshed
- Stars
- 31
- Forks
- 16
- PR merge metrics
- No merged PRs in 30d
Description
My team and I have recently undertaken some work to try and improve the performance of a component that triggers a lot of DOM mutations in a single animation frame. We've instrumented the code to make use of marks and measures, but one area that is a fairly big problem for us is style computation/recalculation and layout.
Take the following (simplified) code, for example:
requestAnimationFrame(() => {
performance.mark("updateElements:start");
updateElements(cachedElements, nextData);
performance.mark("updateElements:end");
});
If updateElements() does simple things with the elements like updating attributes or text content, then our performance measurements are fine. However, if they do things like change class names, position or other styles, our performance measurements do not capture the side effects caused by this and it's difficult to automate collection of such measurements. This is somewhat understandable, since other code on the page could have triggered those side effects rather than our code. However, if we're running in an isolated, predictable environment, then we can know that only our code triggered a style/layout computation.
This is sort of how we're tackling this at the moment:
requestAnimationFrame(() => {
performance.mark("updateElements:start");
updateElements(cachedElements, nextData);
performance.mark("updateElements:end");
setTimeout(() => {
performance.mark("frame:end");
});
});
Measuring between updateElements:end and frame:end gives us a rough idea of the time taken for the browser to compute all the changes, but it's missing important detail and it can run quite late. Is there scope for something that could help with this?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the issue's performance.mark(), requestAnimationFrame(), and setTimeout() examples, then inspect the User Timing specification's existing mark and measure behavior. The issue does not name repository files or tests; completion would require a decided, specified way to account for style computation and layout work, along with corresponding tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- performance, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100