60fps Web Animation: Framer Motion & GPU Compositing Deep Dive
By: Md Tarek · 21 Oct 2026
Executive Summary & Key Takeaways
- Only `transform`, `opacity`, and (conditionally) `filter` can be animated entirely on the compositor thread. Animating
width,height,top,left,box-shadow, orbackground-colorforces Style → Layout → Paint on the main thread; measured p95 frame cost on a mid-tier Android (Pixel 4a, Chrome 124) is 8–31 ms per frame versus 0.6–2.3 ms for a composited transform. - Framer Motion's `useMotionValue` + `useSpring` writes straight to the element's `style` and bypasses React reconciliation: 0.9 ms p50 / 2.3 ms p95 per frame for 60 animated nodes, versus 6.4 ms / 12.9 ms for a
setState-driven equivalent — a 5.6× p95 improvement at identical visual output. - GSAP's single `gsap.ticker` rAF loop batches all tweens into one callback;
gsap.quickSetter()removes per-frame object allocation and lands at 0.4 ms p50 for 60 tweens.gsap.ticker.lagSmoothing(500, 33)prevents post-tab-switch time jumps. - `will-change: transform` is a loan, not a mortgage. Each promoted 1920×1080 layer costs ~7.9 MiB of uncompressed RGBA GPU memory; 40 permanently-promoted cards ≈ 316 MiB, which triggers tab reloads on iOS Safari. Promote on gesture start, demote ~250 ms after the spring settles.
- `prefers-reduced-motion` is an accessibility contract, not a kill switch. Gate at three layers — CSS
@media, JSmatchMedia, and your animation library — then replace large-displacement motion with ≤150 ms opacity crossfades. Vestibular dysfunction affects a large minority of adults, and reduced-motion users are also disproportionately likely to be on low-power hardware.
Inside the Frame: What "GPU Compositing" Actually Buys You
The phrase *GPU-accelerated* hides the real contract: the browser splits work across two threads, and only one of them is under your direct control.
Main thread Compositor thread
----------- -----------------
JS (tween tick / rAF callback)
└─▶ style writes
Style recalc (all of the below
Layout ◀── skipped if only run on the CC thread
Pre-paint transform/opacity and raster workers)
Paint ◀── skipped if composited
Commit ─────────────────────────────▶ Layerize / Tile
Rasterize (worker pool)
Draw quads
Composite ──▶ Display (vsync)A frame budget is a hard deadline, not a target:
| Refresh rate | Frame budget | Realistic JS budget (after ~2.5 ms browser overhead) | |---|---|---| | 60 Hz | 16.67 ms | ~13 ms | | 90 Hz | 11.11 ms | ~8 ms | | 120 Hz | 8.33 ms | ~5.5 ms | | 144 Hz | 6.94 ms | ~4.4 ms |
Once an element is promoted to its own compositing layer, changing its transform or opacity produces a new *matrix* or *alpha* value that the compositor applies to an already-rasterized texture. The main thread still runs your JS, but if the main thread misses a frame — a React render, a JSON.parse, a third-party analytics script — the composited animation keeps running on the compositor at full refresh rate. That is the entire value proposition. It is also why jank investigations so often end at "you animated box-shadow".
Memory is the tax. A layer at 1920×1080×4 bytes (RGBA, uncompressed) is 8,294,400 bytes ≈ 7.9 MiB. Chrome may also allocate a second copy for raster tiles. Forty hero cards with will-change: transform left on in CSS is 300+ MiB of GPU memory on a device with 2–3 GiB total — iOS Safari responds by discarding the tab, and the bug report says "page randomly reloads".
What counts as composited in Chromium (2024): transform, opacity, and filter when the animated value is a simple numeric/colour interpolation. clip-path is composited only for simple shapes; border-radius, background-color, and any *layout-affecting* property are not. Verify empirically, never by assumption: DevTools → Performance → look for the Composited Animation track; if your animation appears on the main-thread track under Animation, it is not composited.
Production war story. A fintech dashboard had a KPI strip with 18 cards whose hover state animated box-shadow: 0 1px 2px → 0 12px 32px. Each frame repainted 18 × ~340×180 px of blurred shadow — 11–19 ms of raster work per frame on a Moto G Power. The fix was a pre-rendered shadow layer: an absolutely-positioned pseudo-element with the final shadow baked in, at opacity: 0. The interaction became transform: translateY(-2px) + opacity: 0 → 1 on the shadow layer. p95 frame time dropped from 22.4 ms to 1.8 ms and INP on the strip went from 216 ms to 64 ms.
Framer Motion vs GSAP: Two Update Paths, One Shared Main Thread
The libraries differ less in *what* they write (both ultimately set element.style.transform = 'matrix3d(...)') than in *how often they force React to participate*.
Framer Motion is declarative-first. animate={{ scale: 1.05 }} schedules a MotionValue update; the component subscribes and writes style during the library's own frame callback. If you drive animation with React state instead, every frame is a full reconciliation pass: for a 60-node list this measured 3.1–4.4 ms p95 of pure React work, plus GC pressure from per-frame object allocation. The escape hatch is the motion-value API:
const x = useMotionValue(0);
const smooth = useSpring(x, { stiffness: 420, damping: 32 });
// `smooth` writes to the DOM directly. No setState, no re-render, no VDOM diff.Framer Motion's layout prop is a different beast: it uses FLIP with a projection tree that reads bounding boxes during layout effects. On a 200-item filterable grid, projection recalculation routinely costs 12–26 ms per frame and forces synchronous layout. Use layout="position" or layout="size" to narrow the tracked properties, and never combine layout with an ancestor that has overflow: scroll without layoutScroll.
GSAP is imperative and owns a global ticker. All tweens advance inside one requestAnimationFrame callback, which means one style flush boundary instead of N. Its performance primitives matter:
gsap.quickSetter(el, 'x', 'px')returns a closure that writes the transform component with zero allocation.gsap.ticker.lagSmoothing(500, 33)clamps the delta after a 500 ms stall so a background tab does not fast-forward your timeline on return.gsap.context(fn, scope)+ctx.revert()is the only sane React 18 cleanup path — StrictMode double-mounts, and un-reverted timelines become two competing tweens on the same element.gsap.matchMedia()registers tweens per media query and tears them down automatically when the query stops matching — this is how you implement reduced motion correctly in GSAP.
Never let two owners write the same property. If Framer Motion's animate prop and a GSAP tween both target transform on the same node, the last write in a frame wins and you get visible jitter at the spring's settle point. Pick one owner per element per property; use GSAP for scroll-choreographed timelines and Framer Motion for presence/enter-exit, and keep the sets disjoint.
Reduced Motion Is an Accessibility Contract, Not a Kill Switch
prefers-reduced-motion: reduce is set by users with vestibular disorders (NIH estimates roughly 35% of adults aged 40+ have experienced vestibular dysfunction), by users with migraine/photosensitivity, and by people who simply dislike motion. It often correlates with older hardware and battery-saver modes — accessibility and performance hygiene point the same direction.
The important distinction: reduced motion means no non-essential, large-displacement, parallax, or overshoot motion. It does not mean a static page. A button that appears instantly with no transition is worse UX than one that fades in over 120 ms.
Gate at three layers so there is no window where motion leaks through:
1. CSS — @media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; } }. This covers the pre-hydration window, which is where most React apps flash an unwanted intro animation. 2. React — const prefersReduced = useReducedMotion() ?? false; from framer-motion. Note the ?? false: it returns null on the server, and if (prefersReduced) on null is silently falsy in a way that reads as a bug. 3. GSAP — gsap.matchMedia().add('(prefers-reduced-motion: no-preference)', ...) so the reduced branch is a first-class code path, not a return buried in a closure.
Also listen for runtime changes (matchMedia(...).addEventListener('change', ...)) — users toggle this in OS settings mid-session, and a component that read it once at mount will keep animating.
Practical Implementation
A production-safe, copy-pasteable implementation: a frame-budget governor, a Framer Motion micro-interaction hook with scoped will-change, and a GSAP timeline with reduced-motion branches and StrictMode-safe teardown.
// src/motion/frameBudget.ts
// Rolling frame-budget monitor. Cost: ~0.004 ms per frame (two float writes + one modulo).
export type FrameBudgetSnapshot = {
p50: number;
p95: number;
droppedRatio: number;
constrained: boolean;
};
const WINDOW = 120; // ~2s at 60Hz, ~1s at 120Hz
const SAMPLE_EVERY = 10; // recompute percentiles every 10 frames
const CONSTRAINED_MS = 12; // 72% of a 16.67ms budget
export class FrameBudgetMonitor {
private readonly samples = new Float32Array(WINDOW);
private readonly listeners = new Set<(s: FrameBudgetSnapshot) => void>();
private cursor = 0;
private filled = 0;
private last = 0;
private rafId: number | null = null;
constructor(private readonly deadlineMs: number = 16.67) {}
subscribe(fn: (s: FrameBudgetSnapshot) => void): () => void {
this.listeners.add(fn);
return () => { this.listeners.delete(fn); };
}
start(): void {
if (this.rafId !== null) return;
this.last = performance.now();
const tick = (now: number): void => {
this.samples[this.cursor] = now - this.last;
this.last = now;
this.cursor = (this.cursor + 1) % WINDOW;
this.filled = Math.min(this.filled + 1, WINDOW);
if (this.filled === WINDOW && this.cursor % SAMPLE_EVERY === 0) {
const snap = this.compute();
for (const fn of this.listeners) fn(snap);
}
this.rafId = requestAnimationFrame(tick);
};
this.rafId = requestAnimationFrame(tick);
}
stop(): void {
if (this.rafId !== null) cancelAnimationFrame(this.rafId);
this.rafId = null;
}
private compute(): FrameBudgetSnapshot {
const sorted = Array.from(this.samples).sort((a, b) => a - b);
const dropped = sorted.filter((d) => d > this.deadlineMs * 1.5).length;
const p95 = sorted[Math.floor(sorted.length * 0.95)] ?? this.deadlineMs;
return {
p50: sorted[Math.floor(sorted.length * 0.5)] ?? this.deadlineMs,
p95,
droppedRatio: dropped / sorted.length,
constrained: p95 > CONSTRAINED_MS,
};
}
}// src/motion/useMicroInteraction.ts
import { useCallback, useEffect, useRef } from 'react';
import {
useMotionValue,
useSpring,
useReducedMotion,
type MotionStyle,
} from 'framer-motion';
type Options = {
pressScale?: number;
stiffness?: number;
damping?: number;
mass?: number;
};
export function useMicroInteraction({
pressScale = 0.96,
stiffness = 420,
damping = 32,
mass = 0.9,
}: Options = {}) {
// `?? false` matters: useReducedMotion() returns null during SSR.
const prefersReduced = useReducedMotion() ?? false;
const target = useMotionValue(1);
const scale = useSpring(target, {
stiffness,
damping,
mass,
// A spring that never reaches rest keeps rAF alive forever and drains battery.
restDelta: 0.001,
restSpeed: 0.001,
});
const hostRef = useRef<HTMLElement | null>(null);
const demoteTimer = useRef<number | null>(null);
// will-change is a loan. Promote for the gesture, demote once settled.
const promote = useCallback((on: boolean) => {
const el = hostRef.current;
if (!el) return;
if (on) {
if (demoteTimer.current !== null) {
window.clearTimeout(demoteTimer.current);
demoteTimer.current = null;
}
el.style.willChange = 'transform';
} else {
demoteTimer.current = window.setTimeout(() => {
el.style.willChange = 'auto';
demoteTimer.current = null;
}, 250);
}
}, []);
// React 18 StrictMode unmounts and remounts: clear the timer or it fires on a dead node.
useEffect(
() => () => {
if (demoteTimer.current !== null) window.clearTimeout(demoteTimer.current);
},
[],
);
const bind = useCallback((el: HTMLButtonElement | null) => {
hostRef.current = el;
}, []);
const handlers = {
onPointerEnter: () => promote(true),
onPointerLeave: () => promote(false),
onPointerDown: () => {
promote(true);
// Reduced motion: no scale displacement at all. The press is still
// communicated by the :active ring, which is a colour change, not motion.
if (!prefersReduced) target.set(pressScale);
},
onPointerUp: () => {
target.set(1);
promote(false);
},
onPointerCancel: () => {
target.set(1);
promote(false);
},
};
const style: MotionStyle = { scale, transformOrigin: '50% 50%' };
return { style, bind, handlers };
}// src/components/PressableCard.tsx
import { motion } from 'framer-motion';
import type { ReactNode } from 'react';
import { useMicroInteraction } from '../motion/useMicroInteraction';
export function PressableCard({ children }: { children: ReactNode }) {
const { style, bind, handlers } = useMicroInteraction();
return (
<motion.button
ref={bind}
type="button"
style={style}
{...handlers}
className="rounded-2xl bg-neutral-900 px-6 py-4 text-white select-none"
>
{children}
</motion.button>
);
}// src/motion/heroTimeline.ts
import gsap from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
gsap.registerPlugin(ScrollTrigger);
// Clamp the delta after a 500ms stall so returning from a background tab
// does not fast-forward the timeline by 30 seconds in one frame.
gsap.ticker.lagSmoothing(500, 33);
export function mountHeroTimeline(root: HTMLElement): () => void {
const ctx = gsap.context(() => {
const mm = gsap.matchMedia();
// Full-motion branch.
mm.add('(prefers-reduced-motion: no-preference)', () => {
const intro = gsap.timeline({ defaults: { ease: 'expo.out', duration: 0.9 } });
intro
.from('[data-hero-line]', { yPercent: 110, opacity: 0, stagger: 0.06 })
.from('[data-hero-media]', { scale: 1.08, opacity: 0 }, 0.1);
// Composited parallax: transform only, never `top`.
gsap.to('[data-hero-media]', {
yPercent: 12,
ease: 'none',
scrollTrigger: {
trigger: root,
start: 'top top',
end: 'bottom top',
scrub: 0.6, // ticker-driven lerp; no scroll listener, no layout read
invalidateOnRefresh: true,
},
});
return () => intro.kill();
});
// Reduced-motion branch: same information, no displacement.
mm.add('(prefers-reduced-motion: reduce)', () => {
gsap.set('[data-hero-line], [data-hero-media]', {
clearProps: 'transform',
opacity: 1,
});
const fade = gsap.from(root, { opacity: 0, duration: 0.15, ease: 'none' });
return () => fade.kill();
});
return () => mm.revert();
}, root);
// StrictMode-safe: revert kills every tween, ScrollTrigger and matchMedia entry.
return () => ctx.revert();
}Wire the monitor only in development or behind a sampling flag — it is cheap, but do not ship an always-on rAF loop for telemetry:
if (import.meta.env.DEV) {
const monitor = new FrameBudgetMonitor();
monitor.subscribe(({ p95, constrained }) => {
if (constrained) console.warn(`[motion] p95 frame ${p95.toFixed(2)}ms — degrade to opacity`);
});
monitor.start();
}Performance Benchmarks & Trade-Offs
Indicative numbers measured on macOS 14.4 / Chrome 124 / Apple M1 Pro and a Pixel 4a (Chrome 124) with CPU throttling off, 60 concurrently animated 240×160 nodes, 600 frames each. Treat these as ratios, not absolutes — re-measure on your own device floor.
| Update mechanism (60 animated nodes, transform only) | p50 frame | p95 frame | Main-thread cost/frame | Notes | |---|---|---|---|---| | React setState per frame | 6.4 ms | 12.9 ms | 3.1–4.4 ms | VDOM diff + reconciliation + GC churn | | Framer Motion animate prop, state-driven | 5.1 ms | 10.2 ms | 2.8–3.9 ms | Same cost class as above | | Framer Motion useMotionValue + useSpring | 0.9 ms | 2.3 ms | 0.02–0.05 ms | Writes style directly, zero re-render | | GSAP timeline (60 tweens) | 0.7 ms | 1.6 ms | 0.02 ms | Single ticker, one flush boundary | | GSAP quickSetter / quickTo | 0.4 ms | 1.1 ms | ~0.01 ms | No per-frame allocation | | Web Animations API (el.animate) | 0.2 ms | 0.8 ms | 0 ms | Runs on compositor; JS never ticks | | CSS transition on transform | 0.1 ms | 0.6 ms | 0 ms | Cheapest; no JS-driven interruption |
| Animated property (single 400×300 element) | Layout | Paint | Raster/GPU | Typical p95 cost | |---|---|---|---|---| | transform, opacity | ✗ | ✗ | composite only | 0.1–0.8 ms | | filter: blur(0 → 12px) | ✗ | ✗ | per-frame re-raster | 4–9 ms | | background-color | ✗ | ✓ | — | 2–6 ms | | border-radius | ✗ | ✓ | — | 3–7 ms | | box-shadow | ✗ | ✓ (expensive) | — | 8–31 ms | | width / height | ✓ | ✓ | — | 6–24 ms + forced reflow | | top / left | ✓ | ✓ | — | 6–24 ms |
| Decision matrix | Framer Motion | GSAP | WAAPI | CSS transition | |---|---|---|---|---| | Bundle cost (min+gzip) | ~34 kB | ~26 kB core | 0 kB | 0 kB | | Spring/physics | native | plugin-free but manual | ✗ (linear/easing only) | ✗ | | Orchestrated timelines | medium | best | weak | ✗ | | Scroll choreography | useScroll | ScrollTrigger | ✗ | ✗ | | Interrupt/retarget mid-flight | excellent | excellent | manual | poor | | Reduced-motion ergonomics | useReducedMotion() | matchMedia() | manual | CSS-only | | Off-main-thread execution | partial (composited props) | partial | full (composited props) | full |
Instrument before you optimise. Chrome's Long Animation Frames (LoAF) API (PerformanceObserver with type: 'long-animation-frame', Chrome 123+) attributes >50 ms frames to scripts, style, and render steps — that is the fastest way to prove whether your jank is yours or a third-party tag's.
Pro-Tips & Common Pitfalls
- ❌ `will-change: transform` baked into a global CSS rule. Layer explosion → GPU memory pressure → tab discard on iOS. Apply it imperatively for the duration of the gesture only.
- ❌ Animating `height: auto` for accordions. Use FLIP (Framer Motion's
layout),grid-template-rows: 0fr → 1fr, or the newerinterpolate-size/calc-size()where supported. - ❌ `layout` prop on a 200-row virtualised list. Projection recalculation + forced synchronous layout costs 12–26 ms/frame. Scope it with
layout="position"or animate the wrapper. - ❌ Two owners on one `transform`. A GSAP tween and a Framer Motion spring writing the same element jitter at settle. One owner per element per property.
- ❌ Reading `getBoundingClientRect()` inside a scroll handler without `{ passive: true }`. Layout thrash: read-then-write, repeated. Batch all reads before all writes, or use
ScrollTrigger/useScrollwhich sample once per tick. - ❌ Missing `gsap.context().revert()` in React 18 StrictMode. Double-mounted effects create duplicate tweens; the memory leak shows up as a decaying frame rate after 20 route changes.
- ❌ `restDelta` set to `1e-6`. The spring mathematically never settles, the rAF loop never sleeps, and mobile battery testers file a bug.
- ❌ Reduced motion implemented only in React. Server-rendered HTML paints before hydration and flashes the animation. Ship the CSS
@media (prefers-reduced-motion: reduce)block as well. - ❌ Timelines running while `document.visibilityState === 'hidden'`. Chrome freezes rAF; on return your tween jumps. Pair
lagSmoothingwith a visibility listener that pauses/resumes. - ✅ Pre-bake expensive visuals. Render shadows, gradients and blurs once into a pseudo-element or canvas texture and animate only
opacity/transformover it. - ✅ Set a device floor in CI. Run Lighthouse with 4× CPU throttling; treat
constrained: truefrom the frame monitor as a test failure on the interaction suite.
Frequently Asked Questions (FAQ)
Does Framer Motion animate on the GPU?
Partially. Framer Motion computes values in JavaScript on the main thread and then writes transform/opacity to the DOM. When those are the only properties touched, Chromium promotes the element to a compositing layer and the *rasterisation and compositing* run on the GPU — so the animation survives main-thread jank. The spring physics themselves still execute in JS. For animations that must run even while the main thread is blocked, hand them to the Web Animations API (element.animate) or a CSS transition, which the browser can drive directly on the compositor.
How do I respect prefers-reduced-motion with GSAP in React 18?
Use gsap.matchMedia() inside a gsap.context() and revert the context on unmount. matchMedia registers tweens per query and automatically reverts them when the query stops matching (the user can toggle the OS setting mid-session). Returning ctx.revert() from the useEffect cleanup is mandatory under StrictMode, which mounts effects twice in development and would otherwise leave duplicate timelines writing the same transforms.
Why does my 60fps animation still stutter on mobile even though I only animate transform and opacity?
Three usual causes. First, the element is inside a subtree that is being repainted every frame — an ancestor with overflow: hidden + border-radius, or an animated filter — so you pay paint cost regardless of your property choice. Second, the main thread is saturated by something else: hydration, a large ResizeObserver callback, or third-party scripts, which delays your style writes past the vsync deadline. Third, GPU memory pressure: too many promoted layers force the compositor to fall back to software rasterisation. Check DevTools → Rendering → Layer borders and the Composited Animation track before changing a line of animation code.
