| name | react-perf |
| description | React and Next.js performance optimization patterns. Use when writing, reviewing, or optimizing React code for web apps, Remotion videos, or any React-based UI. Covers waterfall elimination, bundle optimization, re-render prevention, and server-side patterns. |
| metadata | {"author":"misskim","version":"1.0","origin":"Concept from Vercel react-best-practices (57 rules), distilled to essentials"} |
React Performance Patterns
React ์ฝ๋ ์์ฑ ์ ์ฑ๋ฅ ์ต์ ํ ํต์ฌ ํจํด.
์ฐ์ ์์๋ณ ํต์ฌ ๊ท์น
๐ด CRITICAL: ์ํฐํด ์ ๊ฑฐ
const user = await getUser();
const posts = await getPosts();
const [user, posts] = await Promise.all([getUser(), getPosts()]);
await๋ฅผ ์ค์ ์ฌ์ฉ ๋ธ๋์น๋ก ์ด๋ (๋ถํ์ํ ๋๊ธฐ ์ ๊ฑฐ)
- Suspense ๊ฒฝ๊ณ๋ก ์ฝํ
์ธ ์คํธ๋ฆฌ๋ฐ
๐ด CRITICAL: ๋ฒ๋ค ํฌ๊ธฐ
import { Button } from '@/components';
import { Button } from '@/components/ui/Button';
next/dynamic์ผ๋ก ๋ฌด๊ฑฐ์ด ์ปดํฌ๋ํธ ์ง์ฐ ๋ก๋
- ๋ถ์/๋ก๊น
์ hydration ํ ๋ก๋
- hover/focus ์ preload๋ก ์ฒด๊ฐ ์๋ ํฅ์
๐ก HIGH: ์๋ฒ์ฌ์ด๋
React.cache()๋ก ์์ฒญ ๋ด ์ค๋ณต ์ ๊ฑฐ
- ํด๋ผ์ด์ธํธ๋ก ์ ๋ฌํ๋ ๋ฐ์ดํฐ ์ต์ํ
- ์ปดํฌ๋ํธ ๊ตฌ์กฐ ๋ณ๊ฒฝ์ผ๋ก fetch ๋ณ๋ ฌํ
๐ข MEDIUM: ๋ฆฌ๋ ๋ ๋ฐฉ์ง
const [items, setItems] = useState([]);
const handleClick = () => process(items);
const itemsRef = useRef([]);
const handleClick = () => process(itemsRef.current);
- ๋น์ฉ ๋์ ์์
์ memo ์ปดํฌ๋ํธ๋ก ๋ถ๋ฆฌ
useState ์ด๊ธฐ๊ฐ์ ํจ์ ์ ๋ฌ (lazy init)
startTransition์ผ๋ก ๊ธด๊ธํ์ง ์์ ์
๋ฐ์ดํธ ๋ถ๋ฆฌ
- ํ์ state๋ effect ๋์ ๋ ๋ ์ค ๊ณ์ฐ
๐ต LOW: JS ์ฑ๋ฅ
- ๋ฐ๋ณต ์กฐํ โ
Map/Set ์ฌ์ฉ (O(1))
filter().map() โ ํ๋์ ๋ฃจํ๋ก ๊ฒฐํฉ
- RegExp๋ ๋ฃจํ ๋ฐ์์ ์์ฑ
array.length ๋จผ์ ์ฒดํฌ ํ ๋น์ผ ๋น๊ต
Remotion์์์ React
Remotion ๋น๋์ค ์ปดํฌ๋ํธ๋ React์ด๋ฏ๋ก ๋์ผ ์์น ์ ์ฉ:
interpolate()๋ ๋งค ํ๋ ์ ํธ์ถ โ ๋น์ธ๋ฉด ์บ์ฑ
- ๋ฌด๊ฑฐ์ด ๊ณ์ฐ์
useMemo / useCallback
- ์คํ์คํฌ๋ฆฐ ์์ ๋ ๋๋ง ์ต์ํ