What's causing this excessive "Composite Layers", "Recalculate Style" and "Update Layer Tree" cycle?

Alex Dong picture Alex Dong · Aug 5, 2014 · Viewed 19.3k times · Source

I am very intrigued by the excessive number of "composite layers", "recalculate style" and then "update layer tree" events in one of our webapps. I'm wondering what's causing them here.

If you point your Chrome to one of our fast moving streams, say https://choir.io/player/beachmonks/github, and turn on your "FPS meter", you can see that the app can achieve about 60fps most of the times when we are on the top.

However, as soon as I scroll down a few messages and leave the screen as it is, the FPS rate drops dramatically down to around 10 or even lower. What the code is doing here is that it renders each incoming message, prepends it to the top and scroll the list up Npx, which is the height of the new message, to keep the viewport position intact.

(I understand that scrollTop will invalidate the screen but I have carefully ordered the operations to avoid layout thrashings. I am also aware of the synchronous repaint that happens every second, it's caused by the jquery.sparkline but it's not relevant to this discussion.)

Here is what I see when I tried to profile it. low fps profiling result.

What do you think might be causing the large number of layer operations?

Answer

Anoian picture Anoian · Nov 10, 2016

The CSS property will-change: transform on all elements needing a repaint solved the problem with too many Composite Layers for me.