fixing-motion-performance
Fix animation performance issues.
how to use
Do not migrate animation libraries unless explicitly requested. Apply rules within the existing stack.
When to Use
Reference these guidelines when:
- adding or changing UI animations (CSS, WAAPI, Motion, rAF, GSAP)
- refactoring janky interactions or transitions
- implementing scroll-linked motion or reveal-on-scroll
- animating layout, filters, masks, gradients, or CSS variables
- reviewing components that use will-change, transforms, or measurement
rendering steps glossary
- composite: transform, opacity
- paint: color, borders, gradients, masks, images, filters
- layout: size, position, flow, grid, flex
rule categories by priority
| priority |
category |
impact |
| 1 |
never patterns |
critical |
| 2 |
choose the mechanism |
critical |
| 3 |
measurement |
high |
| 4 |
scroll |
high |
| 5 |
paint |
medium-high |
| 6 |
layers |
medium |
| 7 |
blur and filters |
medium |
| 8 |
view transitions |
low |
| 9 |
tool boundaries |
critical |
quick reference
1. never patterns (critical)
- do not interleave layout reads and writes in the same frame
- do not animate layout continuously on large or meaningful surfaces
- do not drive animation from scrollTop, scrollY, or scroll events
- no requestAnimationFrame loops without a stop condition
- do not mix multiple animation systems that each measure or mutate layout
2. choose the mechanism (critical)
- default to transform and opacity for motion
- use JS-driven animation only when interaction requires it
- paint or layout animation is acceptable only on small, isolated surfaces
- one-shot effects are acceptable more often than continuous motion
- prefer downgrading technique over removing motion entirely
3. measurement (high)
- measure once, then animate via transform or opacity
- batch all DOM reads before writes
- do not read layout repeatedly during an animation
- prefer FLIP-style transitions for layout-like effects
- prefer approaches that batch measurement and writes
4. scroll (high)
- prefer Scroll or View Timelines for scroll-linked motion when available
- use IntersectionObserver for visibility and pausing
- do not poll scroll position for animation
- pause or stop animations when off-screen
- scroll-linked motion must not trigger continuous layout or paint on large surfaces
5. paint (medium-high)
- paint-triggering animation is allowed only on small, isolated elements
- do not animate paint-heavy properties on large containers
- do not animate CSS variables for transform, opacity, or position
- do not animate inherited CSS variables
- scope animated CSS variables locally and avoid inheritance
6. layers (medium)
- compositor motion requires layer promotion, never assume it
- use will-change temporarily and surgically
- avoid many or large promoted layers
- validate layer behavior with tooling when performance matters
7. blur and filters (medium)
- keep blur animation small (<=8px)
- use blur only for short, one-time effects
- never animate blur continuously
- never animate blur on large surfaces
- prefer opacity and translate before blur
8. view transitions (low)
- use view transitions only for navigation-level changes
- avoid view transitions for interaction-heavy UI
- avoid view transitions when interruption or cancellation is required
- treat size changes as potentially layout-triggering
9. tool boundaries (critical)
- do not migrate or rewrite animation libraries unless explicitly requested
- apply these rules within the existing animation system
- never partially migrate APIs or mix styles within the same component
common fixes
/* layout thrashing: animate transform instead of width */
/* before */ .panel { transition: width 0.3s; }
/* after */ .panel { transition: transform 0.3s; }
/* scroll-linked: use scroll-timeline instead of JS */
/* before */ window.addEventListener('scroll', () => el.style.opacity = scrollY / 500)
/* after */ .reveal { animation: fade-in linear; animation-timeline: view(); }
// measurement: batch reads before writes (FLIP)
// before — layout thrash
el.style.left = el.getBoundingClientRect().left + 10 + 'px';
// after — measure once, animate via transform
const first = el.getBoundingClientRect();
el.classList.add('moved');
const last = el.getBoundingClientRect();
el.style.transform = `translateX(${first.left - last.left}px)`;
requestAnimationFrame(() => { el.style.transition = 'transform 0.3s'; el.style.transform = ''; });
review guidance
- enforce critical rules first (never patterns, tool boundaries)
- choose the least expensive rendering work that matches the intent
- for any non-default choice, state the constraint that justifies it (surface size, duration, or interaction requirement)
- when reviewing, prefer actionable notes and concrete alternatives over theory
When to Use
This skill is applicable to execute the workflow or actions described in the overview.
1---2name: fixing-motion-performance3description: Audit and fix animation performance issues including layout thrashing,4 compositor properties, scroll-linked motion, and blur effects. Use when animations5 stutter, transitions jank, or reviewing CSS/JS animation performance.6risk: safe7source: community8license: MIT9metadata:10 source: https://skillmd.com/skills/jantoniofc/fixing-motion-performance11---1213# fixing-motion-performance1415Fix animation performance issues.1617## how to use1819- `/fixing-motion-performance`20 Apply these constraints to any UI animation work in this conversation.2122- `/fixing-motion-performance <file>`23 Review the file against all rules below and report:24 - violations (quote the exact line or snippet)25 - why it matters (one short sentence)26 - a concrete fix (code-level suggestion)2728Do not migrate animation libraries unless explicitly requested. Apply rules within the existing stack.2930## When to Use31Reference these guidelines when:32- adding or changing UI animations (CSS, WAAPI, Motion, rAF, GSAP)33- refactoring janky interactions or transitions34- implementing scroll-linked motion or reveal-on-scroll35- animating layout, filters, masks, gradients, or CSS variables36- reviewing components that use will-change, transforms, or measurement3738## rendering steps glossary3940- composite: transform, opacity41- paint: color, borders, gradients, masks, images, filters42- layout: size, position, flow, grid, flex4344## rule categories by priority4546| priority | category | impact |47|----------|----------|--------|48| 1 | never patterns | critical |49| 2 | choose the mechanism | critical |50| 3 | measurement | high |51| 4 | scroll | high |52| 5 | paint | medium-high |53| 6 | layers | medium |54| 7 | blur and filters | medium |55| 8 | view transitions | low |56| 9 | tool boundaries | critical |5758## quick reference5960### 1. never patterns (critical)6162- do not interleave layout reads and writes in the same frame63- do not animate layout continuously on large or meaningful surfaces64- do not drive animation from scrollTop, scrollY, or scroll events65- no requestAnimationFrame loops without a stop condition66- do not mix multiple animation systems that each measure or mutate layout6768### 2. choose the mechanism (critical)6970- default to transform and opacity for motion71- use JS-driven animation only when interaction requires it72- paint or layout animation is acceptable only on small, isolated surfaces73- one-shot effects are acceptable more often than continuous motion74- prefer downgrading technique over removing motion entirely7576### 3. measurement (high)7778- measure once, then animate via transform or opacity79- batch all DOM reads before writes80- do not read layout repeatedly during an animation81- prefer FLIP-style transitions for layout-like effects82- prefer approaches that batch measurement and writes8384### 4. scroll (high)8586- prefer Scroll or View Timelines for scroll-linked motion when available87- use IntersectionObserver for visibility and pausing88- do not poll scroll position for animation89- pause or stop animations when off-screen90- scroll-linked motion must not trigger continuous layout or paint on large surfaces9192### 5. paint (medium-high)9394- paint-triggering animation is allowed only on small, isolated elements95- do not animate paint-heavy properties on large containers96- do not animate CSS variables for transform, opacity, or position97- do not animate inherited CSS variables98- scope animated CSS variables locally and avoid inheritance99100### 6. layers (medium)101102- compositor motion requires layer promotion, never assume it103- use will-change temporarily and surgically104- avoid many or large promoted layers105- validate layer behavior with tooling when performance matters106107### 7. blur and filters (medium)108109- keep blur animation small (<=8px)110- use blur only for short, one-time effects111- never animate blur continuously112- never animate blur on large surfaces113- prefer opacity and translate before blur114115### 8. view transitions (low)116117- use view transitions only for navigation-level changes118- avoid view transitions for interaction-heavy UI119- avoid view transitions when interruption or cancellation is required120- treat size changes as potentially layout-triggering121122### 9. tool boundaries (critical)123124- do not migrate or rewrite animation libraries unless explicitly requested125- apply these rules within the existing animation system126- never partially migrate APIs or mix styles within the same component127128## common fixes129130```css131/* layout thrashing: animate transform instead of width */132/* before */ .panel { transition: width 0.3s; }133/* after */ .panel { transition: transform 0.3s; }134135/* scroll-linked: use scroll-timeline instead of JS */136/* before */ window.addEventListener('scroll', () => el.style.opacity = scrollY / 500)137/* after */ .reveal { animation: fade-in linear; animation-timeline: view(); }138```139140```js141// measurement: batch reads before writes (FLIP)142// before — layout thrash143el.style.left = el.getBoundingClientRect().left + 10 + 'px';144// after — measure once, animate via transform145const first = el.getBoundingClientRect();146el.classList.add('moved');147const last = el.getBoundingClientRect();148el.style.transform = `translateX(${first.left - last.left}px)`;149requestAnimationFrame(() => { el.style.transition = 'transform 0.3s'; el.style.transform = ''; });150```151152## review guidance153154- enforce critical rules first (never patterns, tool boundaries)155- choose the least expensive rendering work that matches the intent156- for any non-default choice, state the constraint that justifies it (surface size, duration, or interaction requirement)157- when reviewing, prefer actionable notes and concrete alternatives over theory158159## When to Use160This skill is applicable to execute the workflow or actions described in the overview.