9148c358d0
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를 Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류. - 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로 자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거, 동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거. - 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming, Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business, Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로, 나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는 title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백). 원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지. - 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서. - 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는 지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지. - Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경. - 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
201 lines
5.7 KiB
Markdown
201 lines
5.7 KiB
Markdown
---
|
|
id: wiki-2026-0508-time-slicing
|
|
title: Time Slicing
|
|
category: 10_Wiki/Topics
|
|
status: verified
|
|
canonical_id: self
|
|
aliases: [타임 슬라이싱, Concurrent Rendering, React Concurrent]
|
|
duplicate_of: none
|
|
source_trust_level: A
|
|
confidence_score: 0.9
|
|
verification_status: applied
|
|
tags: [react, performance, concurrent, scheduling]
|
|
raw_sources: []
|
|
last_reinforced: 2026-05-10
|
|
github_commit: pending
|
|
tech_stack:
|
|
language: typescript
|
|
framework: react-19
|
|
---
|
|
|
|
# Time Slicing
|
|
|
|
## 매 한 줄
|
|
> **"매 long render 를 작은 chunk 로 쪼개 매 main thread 의 yield"**. React 18+ Concurrent Rendering 의 core mechanism — `startTransition`, `useDeferredValue`, Suspense 가 매 expose. 2026 React 19 + Activity API 가 매 확장.
|
|
|
|
## 매 핵심
|
|
|
|
### 매 동작
|
|
- React scheduler 가 매 5ms budget 단위로 work.
|
|
- 매 budget exceed 시 `MessageChannel` 로 yield.
|
|
- 매 input event / paint 의 우선 처리.
|
|
- 매 interruptible — 매 render 가 stale 되면 throw away.
|
|
|
|
### 매 priority
|
|
- **Sync/Discrete** (click, input): 즉시.
|
|
- **Continuous** (mouseover, scroll): high.
|
|
- **Transition** (`startTransition`): low — interruptible.
|
|
- **Idle**: 매 background.
|
|
|
|
### 매 응용
|
|
1. 매 large list filter 의 typing lag 방지.
|
|
2. 매 tab switch 의 immediate response.
|
|
3. 매 search-as-you-type — stale 결과 throw away.
|
|
|
|
## 💻 패턴
|
|
|
|
### `startTransition`
|
|
```tsx
|
|
import { startTransition, useState } from 'react';
|
|
|
|
function SearchPage() {
|
|
const [input, setInput] = useState('');
|
|
const [query, setQuery] = useState('');
|
|
|
|
return (
|
|
<input
|
|
value={input}
|
|
onChange={(e) => {
|
|
setInput(e.target.value); // 매 urgent — 즉시 반영
|
|
startTransition(() => {
|
|
setQuery(e.target.value); // 매 transition — interruptible
|
|
});
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
```
|
|
|
|
### `useTransition` with pending
|
|
```tsx
|
|
import { useTransition, useState } from 'react';
|
|
|
|
function TabSwitcher() {
|
|
const [tab, setTab] = useState<'a' | 'b' | 'c'>('a');
|
|
const [isPending, startTransition] = useTransition();
|
|
|
|
return (
|
|
<>
|
|
<nav style={{ opacity: isPending ? 0.6 : 1 }}>
|
|
{(['a', 'b', 'c'] as const).map(t => (
|
|
<button key={t} onClick={() => startTransition(() => setTab(t))}>
|
|
{t}
|
|
</button>
|
|
))}
|
|
</nav>
|
|
{tab === 'a' && <HeavyA />}
|
|
{tab === 'b' && <HeavyB />}
|
|
{tab === 'c' && <HeavyC />}
|
|
</>
|
|
);
|
|
}
|
|
```
|
|
|
|
### `useDeferredValue`
|
|
```tsx
|
|
import { useDeferredValue, useState, memo } from 'react';
|
|
|
|
function App() {
|
|
const [text, setText] = useState('');
|
|
const deferred = useDeferredValue(text);
|
|
// 매 deferred 는 lag behind — 매 heavy list 가 매 stale value 로 render
|
|
|
|
return (
|
|
<>
|
|
<input value={text} onChange={(e) => setText(e.target.value)} />
|
|
<SlowList query={deferred} />
|
|
</>
|
|
);
|
|
}
|
|
|
|
const SlowList = memo(function SlowList({ query }: { query: string }) {
|
|
// 매 expensive filter — 매 transition 으로 interruptible
|
|
const items = bigDataset.filter(d => d.includes(query));
|
|
return <ul>{items.map(i => <li key={i}>{i}</li>)}</ul>;
|
|
});
|
|
```
|
|
|
|
### React 19 Activity (formerly Offscreen)
|
|
```tsx
|
|
import { Activity } from 'react';
|
|
|
|
function TabContainer({ active }: { active: 'a' | 'b' }) {
|
|
return (
|
|
<>
|
|
<Activity mode={active === 'a' ? 'visible' : 'hidden'}>
|
|
<HeavyA />
|
|
</Activity>
|
|
<Activity mode={active === 'b' ? 'visible' : 'hidden'}>
|
|
<HeavyB />
|
|
</Activity>
|
|
</>
|
|
);
|
|
// 매 hidden 매 unmount 안함 — state 보존, 매 background pre-render
|
|
}
|
|
```
|
|
|
|
### Manual time slicing (low-level)
|
|
```typescript
|
|
// 매 React 외부에서 — 매 scheduler/postTask
|
|
async function processInChunks<T>(items: T[], fn: (x: T) => void) {
|
|
const CHUNK = 50;
|
|
for (let i = 0; i < items.length; i += CHUNK) {
|
|
items.slice(i, i + CHUNK).forEach(fn);
|
|
if ('scheduler' in window && 'yield' in (window as any).scheduler) {
|
|
await (window as any).scheduler.yield();
|
|
} else {
|
|
await new Promise(r => setTimeout(r, 0));
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
### Detecting jank
|
|
```typescript
|
|
// 매 Long Animation Frame API (Chrome 123+)
|
|
const obs = new PerformanceObserver((list) => {
|
|
for (const entry of list.getEntries()) {
|
|
if (entry.duration > 50) {
|
|
console.warn('Long task:', entry.duration, 'ms', entry);
|
|
}
|
|
}
|
|
});
|
|
obs.observe({ type: 'long-animation-frame', buffered: true });
|
|
```
|
|
|
|
## 매 결정 기준
|
|
| 상황 | Approach |
|
|
|---|---|
|
|
| 매 typing lag (heavy list) | `useDeferredValue` |
|
|
| 매 tab/route switch | `useTransition` + Suspense |
|
|
| 매 explicit user-initiated heavy update | `startTransition` |
|
|
| 매 hidden tab pre-warm | Activity (React 19) |
|
|
| 매 non-React heavy work | `scheduler.yield()` / chunking |
|
|
|
|
**기본값**: 매 heavy render → `useDeferredValue`. 매 user action → `startTransition`.
|
|
|
|
## 🔗 Graph
|
|
- 부모: [[React]] · [[Concurrent_Rendering]]
|
|
- 변형: [[Suspense]]
|
|
- 응용: [[useTransition]] · [[useDeferredValue]] · [[startTransition]]
|
|
|
|
## 🤖 LLM 활용
|
|
**언제**: 매 `startTransition` placement, 매 jank diagnosis, 매 deferred value introduction.
|
|
**언제 X**: 매 root cause 가 매 algorithm — 매 time slicing 으로 fix 안됨. 매 actual optimization 필요.
|
|
|
|
## ❌ 안티패턴
|
|
- **`startTransition` everywhere**: 매 input 까지 transition → 매 lag 보임.
|
|
- **Heavy work in transition without memo**: 매 매번 re-run.
|
|
- **Forgetting Suspense boundary**: 매 fallback 안 보임.
|
|
- **Time slicing as algorithm fix**: 매 O(n²) 는 여전히 O(n²).
|
|
|
|
## 🧪 검증 / 중복
|
|
- Verified (React 19 docs, React Conf 2024, Andrew Clark talks, 2026).
|
|
- 신뢰도 A.
|
|
|
|
## 🕓 Changelog
|
|
| 날짜 | 변경 |
|
|
|---|---|
|
|
| 2026-05-08 | Phase 1 |
|
|
| 2026-05-10 | Manual cleanup — React 19 time slicing with Activity API, scheduler.yield |
|