--- id: wiki-2026-0508-애니메이션-transition-keyframes-성능-최적 title: 애니메이션 (transition / keyframes) 성능 최적화 category: 10_Wiki/Topics status: verified canonical_id: self aliases: [CSS Animation Performance, GPU 합성 애니메이션, transform/opacity 최적화] duplicate_of: none source_trust_level: A confidence_score: 0.92 verification_status: applied tags: [frontend, css, animation, performance, gpu, compositor] raw_sources: [] last_reinforced: 2026-05-10 github_commit: pending tech_stack: language: CSS framework: Web Platform (Chromium 130+, Safari 18+, Firefox 130+) --- # 애니메이션 (transition / keyframes) 성능 최적화 ## 매 한 줄 > **"매 transform 과 opacity 만이 GPU 합성 layer 위에서 60/120fps 으로 부드럽게 흐른다"**. 매 layout 또는 paint 를 trigger 하는 property (width, height, top, left, margin) 의 animate 는 매 main thread CPU 의 reflow 를 매 frame 마다 강제 → jank. 매 2026 modern web (CH 130+, Safari 18+) 의 compositor-only animation 의 사용 — `will-change`, `contain`, `view-transition-name` 매 핵심. ## 매 핵심 ### 매 Rendering Pipeline 의 4 단계 - **Style** — CSS rule 매 element 매 매칭. - **Layout (reflow)** — 매 geometry 의 계산 (position, size). 매 비싼 단계. - **Paint** — pixel buffer 매 fill (color, image, shadow). - **Composite** — GPU 매 layer 의 합성 (transform, opacity). - 매 transform/opacity 매 변경 시 매 Composite 만 trigger → 매 main thread block 의 X. ### 매 GPU 합성 trigger - `transform` (translate, rotate, scale, skew) — 매 layout 의 영향 X. - `opacity` — 매 paint 의 영향 X. - `filter` — 매 composited layer 위 의 GPU shader. - `clip-path` (transform 기반) — 매 GPU friendly. ### 매 비싼 properties (피해야 함) 1. `width`, `height`, `top`, `left`, `margin`, `padding` — 매 reflow 매 trigger. 2. `box-shadow`, `border-radius` (애니메이트 시) — 매 paint 매 매 frame. 3. `background-image` — 매 paint trigger. 4. `font-size` — 매 reflow + paint. ## 💻 패턴 ### Pattern 1: position 의 transform 으로 변환 ```css /* ❌ Bad: layout thrashing */ .move-bad { transition: left 300ms ease-out; position: absolute; left: 0; } .move-bad:hover { left: 200px; } /* ✅ Good: GPU composite only */ .move-good { transition: transform 300ms ease-out; transform: translateX(0); will-change: transform; } .move-good:hover { transform: translateX(200px); } ``` ### Pattern 2: opacity fade-in 의 keyframes ```css @keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } } .card { animation: fadeIn 400ms cubic-bezier(0.16, 1, 0.3, 1) both; } ``` ### Pattern 3: will-change 의 신중한 사용 ```css /* ❌ Bad: layer 의 영구 promotion → memory bloat */ .everywhere { will-change: transform; } /* ✅ Good: 매 interaction 직전 의 hint, 매 종료 후 매 제거 */ .button { transition: transform 200ms; } .button:hover { will-change: transform; } .button:not(:hover) { will-change: auto; } /* JS 의 dynamic toggle */ btn.addEventListener('mouseenter', () => btn.style.willChange = 'transform'); btn.addEventListener('animationend', () => btn.style.willChange = 'auto'); ``` ### Pattern 4: contain 의 layout 격리 ```css .list-item { contain: layout paint style; /* 매 child 의 reflow 매 ancestor 의 propagate 의 X */ } .modal { contain: strict; /* layout + paint + size + style */ } ``` ### Pattern 5: View Transitions API (2026 stable) ```css /* 매 navigation 의 자동 cross-fade — Chrome 130+, Safari 18+ */ @view-transition { navigation: auto; } ::view-transition-old(card), ::view-transition-new(card) { animation-duration: 400ms; } .card[data-id="42"] { view-transition-name: card-42; } ``` ```js // SPA 의 trigger document.startViewTransition(() => { renderNewState(); }); ``` ### Pattern 6: requestAnimationFrame 의 JS animation ```js function smoothScroll(target) { const start = window.scrollY; const distance = target - start; const duration = 400; let startTime = null; function step(t) { if (!startTime) startTime = t; const elapsed = t - startTime; const progress = Math.min(elapsed / duration, 1); const eased = 1 - Math.pow(1 - progress, 3); // easeOutCubic window.scrollTo(0, start + distance * eased); if (progress < 1) requestAnimationFrame(step); } requestAnimationFrame(step); } ``` ### Pattern 7: Web Animations API (declarative + JS control) ```js const anim = element.animate( [ { transform: 'translateX(0)', opacity: 0 }, { transform: 'translateX(100px)', opacity: 1 } ], { duration: 500, easing: 'cubic-bezier(0.4, 0, 0.2, 1)', fill: 'forwards' } ); anim.onfinish = () => element.style.willChange = 'auto'; anim.pause(); // scrubbing 의 가능 ``` ### Pattern 8: prefers-reduced-motion 의 존중 ```css @media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } } ``` ### Pattern 9: transform 의 3D promotion (legacy) ```css /* 매 Safari 의 layer promotion 의 강제 — 2026 매 거의 불필요 (will-change 의 사용) */ .legacy-promoted { transform: translateZ(0); /* 또는 backface-visibility: hidden; */ } ``` ## 매 결정 기준 | 상황 | Approach | |---|---| | Hover micro-interaction | `transition: transform, opacity` | | Page navigation | View Transitions API | | Complex sequence | `@keyframes` + `animation-*` | | JS-controlled scrub | Web Animations API | | Scroll-linked | `animation-timeline: scroll()` (CSS Scroll-driven, 2026 stable) | | Heavy DOM list | `contain: layout paint` 의 격리 | | Accessibility | `prefers-reduced-motion` 의 fallback | **기본값**: `transform` + `opacity` 매 transition, 매 will-change 의 interaction-scoped 의 toggle. ## 🔗 Graph - 부모: [[웹 프론트엔드 성능 최적화|Frontend Performance Optimization (FE 성능 최적화)]] - 변형: [[View Transitions API]] - Adjacent: [[Web Worker (웹 워커)|Web Workers]] · [[GPU Compositing]] · [[Lighthouse]] ## 🤖 LLM 활용 **언제**: animation jank 의 진단, will-change 의 적절한 scope 의 권고, layout-trigger property 의 transform 의 변환. **언제 X**: 매 specific timing curve 의 design 결정 — 매 designer 의 영역. ## ❌ 안티패턴 - **Animate `top`/`left`/`width`/`height`**: 매 reflow 매 frame, jank 의 보장. - **`will-change` 의 globalsync**: 매 모든 element 의 promotion → GPU memory exhaustion. - **`@keyframes` 의 box-shadow animate**: 매 paint 의 매 frame, 매 mobile 의 dropped frames. - **JavaScript setInterval 의 animation**: 매 rAF 의 사용 — 매 vsync 의 sync 의 X. - **prefers-reduced-motion 의 무시**: 매 vestibular disorder user 의 motion sickness. ## 🧪 검증 / 중복 - Verified (web.dev: Animations performance, Chrome DevTools Performance panel, MDN CSS Animations 2026). - 신뢰도 A. ## 🕓 Changelog | 날짜 | 변경 | |---|---| | 2026-05-08 | Phase 1 | | 2026-05-10 | Manual cleanup — GPU compositor pipeline, will-change scope, View Transitions API patterns |