Compositor-Only Animations
why left stutters and transform doesn't
Web developmentweb development / animation performance
Four stages per frame
The browser turns CSS into pixels in a fixed order:
style → layout → paint → composite
Which property you animate decides how far back into that pipeline every single frame has to go. That's the whole lesson.
Two ways to slide a panel
/* A — touches layout, 60x per second */
.panel { transition: left 300ms; }
.panel.open { left: 0; }
/* B — composite only */
.panel { transition: transform 300ms; }
.panel.open { transform: translateX(0); }
- A: every frame recomputes geometry for the panel and anything its position affects, repaints, then composites — all on the main thread.
- B: the panel is already rasterized into a texture. Each frame the compositor just draws that texture at a new offset, on its own thread.
Only four properties are composite-only: transform, opacity, filter, backdrop-filter. Everything else costs at least a paint.
The part people miss
This isn't "B is 20% faster". A composited animation keeps running while the main thread is blocked.
button.onclick = () => {
panel.classList.add('open'); // start the animation
renderBigTable(); // 400ms of main-thread work
}
Version B animates smoothly through those 400ms. Version A freezes solid, then snaps to the end. Same story for a long GC pause or a heavy third-party script.
Two traps
- JS-driven transform is not composited. Setting
el.style.transforminside arequestAnimationFrameloop still needs the main thread every frame. Only CSS transitions/animations andelement.animate()hand the work off to the compositor. will-changeis not a "go faster" switch. It promotes the element to its own GPU layer, and a layer costsw × h × 4bytes of texture memory — one full-screen 1920×1080 layer is ~8 MB.will-change: transformon 200 list items is how you OOM a mid-range Android. Add it just before the animation and remove it after, or leave it off entirely: browsers promote automatically for composited animations.
Prove it in 2 minutes
DevTools → Rendering panel → enable Paint flashing and Layer borders. Run both versions: A flashes green on every frame, B doesn't. Then record in the Performance tab — A's frames pile up on "Recalculate Style" and "Layout", B's show only "Composite Layers" with an idle main thread.
Your exercise
Find one animation in your app that moves width, height, top or margin. Rewrite it with transform (scale() for size, translate() for position) plus opacity. Profile both with CPU throttling at 4× and compare dropped frames.
Bonus question: why does transform: scale() make text look slightly soft mid-animation — and what does that tell you about when the texture was rasterized?