The evening parade: the main thread is really kept busy; what still moves, transform, opacity, left or box-shadow? Each frame’s rendering work is timed, layer…
Why it matters
A stuttering animation almost always means the main thread was late with a frame. Choosing properties the compositor can run makes animation survive busy JavaScript. will-change helps prepare the layer early, but every layer costs memory.
The key idea
What the compositor can run keeps moving while the main thread stands still
Common mistakes
Why does an animation on left stutter?left and top force layout and paint every frame on the main thread, so the animation stops whenever the main thread is busy. Use transform: translate(): it looks the same, and the compositor can run it.
Putting will-change on every element to be fast Every element with will-change can become a layer of its own, its picture kept in GPU memory, and its size decides the cost: one element as big as the screen can take several megabytes. Set it only on what will move, just before, and take it off after.
box-shadow moves no layout, so it is free? Moving no layout is not free: the shadow is painted again every frame, on the main thread. For a pulsing glow, paint the shadow once on its own element (or a pseudo-element) and animate its opacity.
Try it in this playground
Keep the main thread busy during the parade Zero frames from the main thread; Bagas and Dina keep moving.
Swing the lanterns by left, then transform Their main-thread rendering work per frame is far apart.
Pulse the glow by box-shadow, then opacity Moving no layout is not the same as free.
Set will-change on the evening sky One big element, a big estimated layer memory.