[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,104 +2,169 @@
|
||||
id: wiki-2026-0508-lanes-model
|
||||
title: Lanes Model
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: []
|
||||
aliases: [React Lanes, React Priority Lanes, Concurrent Lanes]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
tags: [uncategorized]
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [react, scheduler, concurrent, lanes]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-08
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: javascript
|
||||
framework: react
|
||||
---
|
||||
|
||||
# [[Lanes Model|Lanes Model]]
|
||||
# Lanes Model
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
Lanes Model은 React의 Fiber 아키텍처에서 동시성(Concurrent) 작업과 렌더링의 우선순위를 관리하기 위해 도입된 정교한 시스템입니다 [1]. 32비트 정수 형태의 비트마스크(bitmask)를 활용하여 UI 업데이트 작업을 여러 우선순위 레벨(Lane)로 분류하고 관리합니다 [2]. 이를 통해 즉각적인 사용자 상호작용과 같은 긴급한 업데이트를 우선적으로 처리하며, 무거운 연산 중에도 UI의 반응성을 유지하도록 돕습니다 [3, 4].
|
||||
## 매 한 줄
|
||||
> **"매 31-bit bitmask 로 매 scheduling priority 를 매 표현 — 매 concurrent React 의 매 심장."**. React 18+ 의 매 Lanes 는 매 expiration time model 을 매 대체. 매 multiple priority 의 매 update 가 매 동시에 매 진행, 매 batch 가 매 lane group 단위. 매 2026 React 19 도 매 동일 model.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
* **작동 원리 및 비트마스크 시스템:**
|
||||
React의 Lanes Model은 각 'Lane'이 작업의 우선순위 또는 범주를 나타내는 32비트 정수 비트마스크 시스템을 사용합니다 [2]. 비트 연산(`lanes & otherLanes`)을 활용하여 작업 간의 우선순위 중첩 여부를 매우 빠르고 효율적으로 확인합니다 [5]. 상태 업데이트가 발생하면 React는 해당 작업의 중요도에 따라 Lane을 할당하며, 렌더링 단계(Render phase)에서 우선순위가 가장 높은 Lane부터 처리합니다 [5].
|
||||
## 매 핵심
|
||||
|
||||
* **우선순위 레벨 (Priority Lanes):**
|
||||
작업은 중요도에 따라 다음과 같은 주요 Lane으로 분류됩니다 [3, 6].
|
||||
* **Sync Lane:** 타이핑이나 클릭과 같은 이산적인 사용자 입력입니다. 화면이 멈추는 것을 방지하기 위해 즉시(동기적으로) 처리되며 다른 작업에 의해 차단되지 않습니다 [3, 6, 7].
|
||||
* **InputContinuous Lane:** 스크롤이나 마우스 호버처럼 연속적인 입력입니다. 유동적인 모션을 보장하기 위해 높은 우선순위를 갖습니다 [3, 6, 7].
|
||||
* **Default Lane:** 데이터 페칭 결과 처리 등 대부분의 일반적인 상태 업데이트에 부여되는 기본 우선순위입니다 [3, 6, 7].
|
||||
* **Idle Lane:** 화면 밖의 렌더링과 같이 브라우저가 유휴(Idle) 상태일 때만 백그라운드에서 처리되는 작업입니다 [3, 6, 7].
|
||||
### 매 Bitmask 정의 (`ReactFiberLane.js`)
|
||||
- 31 lanes. Bit 0 (rightmost) = 매 highest priority.
|
||||
- **SyncLane** = `0b0000000000000000000000000000001` — 매 click, input.
|
||||
- **InputContinuousLane** — 매 drag, scroll.
|
||||
- **DefaultLane** — 매 useEffect setState 등.
|
||||
- **TransitionLanes** (16 lanes) — 매 startTransition.
|
||||
- **RetryLanes** — 매 Suspense retry.
|
||||
- **IdleLane** — 매 lowest.
|
||||
- **OffscreenLane** — 매 hidden subtree.
|
||||
|
||||
* **Lanes Model의 핵심 최적화 기능:**
|
||||
* **우선순위 선점 및 중단:** 렌더링 중 더 높은 우선순위의 업데이트가 도착하면, 진행 중이던 낮은 우선순위의 작업(WIP, Work-In-Progress)을 일시 중지하고 높은 우선순위의 작업을 먼저 처리할 수 있습니다 [5, 8].
|
||||
* **기아 현상 방지 (Starvation Prevention):** 낮은 우선순위의 작업이 오랫동안 대기 상태에 머물러 처리되지 못하는 것을 막기 위해, 일정 시간이 지나면 더 높은 우선순위 Lane으로 승격(promote)시켜 실행을 보장합니다 [5].
|
||||
* **작업 얽힘 (Ent[[ANGLE|ANGLE]]ment):** 낮은 우선순위의 업데이트가 높은 우선순위 업데이트의 결과에 의존해야 할 경우, 두 Lane을 서로 얽히게 만들어 함께 렌더링되도록 동기화합니다 [5].
|
||||
### 매 Lane 연산
|
||||
- **Merge**: `a | b` — 매 여러 update 의 매 lane 합집합.
|
||||
- **Subset**: `(a & b) === a` — 매 a 가 매 b 안에.
|
||||
- **Higher priority**: 매 lower bit. `getHighestPriorityLane = lanes & -lanes`.
|
||||
- **Pending**: 매 fiber.lanes / fiber.childLanes — 매 자기 + 매 subtree 의 매 pending.
|
||||
|
||||
* **동시성 기능(Concurrent Features)의 기반:**
|
||||
Lanes Model은 React의 `[[useTransition|useTransition]]` 및 `[[useDeferredValue|useDeferredValue]]`와 같은 동시성 훅(Hooks)을 구동하는 핵심 기술입니다 [4]. 이 모델 덕분에 긴급하지 않은 렌더링 업데이트를 낮은 우선순위로 미뤄두어, 무거운 연산이 진행되는 동안에도 UI가 멈추지 않고 반응성을 유지할 수 있습니다 [4].
|
||||
### 매 Lifecycle
|
||||
1. setState → `requestUpdateLane()` → 매 lane 결정 (event type / context).
|
||||
2. `markRootUpdated(root, lane)` → root.pendingLanes 에 매 OR.
|
||||
3. `ensureRootIsScheduled` → 매 highest priority lane 의 매 next render schedule.
|
||||
4. `performConcurrentWorkOnRoot` → 매 lane subset render. 매 yieldable.
|
||||
5. Commit 시 매 finishedLanes 를 매 pendingLanes 에서 매 clear.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** [[React Fiber Architecture|React Fiber Architecture]], Concurrent Rendering, React Scheduler, [[Virtual DOM|Virtual DOM]]
|
||||
- **Projects/Contexts:** React의 렌더링 최적화 및 우선순위 기반 스케줄링 맥락
|
||||
- **Contradictions/Notes:** 소스 간의 모순점은 발견되지 않았습니다. 제공된 소스들은 공통적으로 Lanes Model이 React의 우선순위 관리와 동시성 렌더링을 가능하게 하는 중추적인 아키텍처임을 강조합니다.
|
||||
### 매 응용
|
||||
1. startTransition — 매 user input 과 매 분리.
|
||||
2. useDeferredValue — 매 stale value 표시.
|
||||
3. Suspense retry — 매 별도 lane 으로 매 burst 방지.
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-25*
|
||||
## 💻 패턴
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### Lane bitmask 기본
|
||||
```javascript
|
||||
// React internal
|
||||
const SyncLane = /* */ 0b0000000000000000000000000000001;
|
||||
const InputContinuousLane = /* */ 0b0000000000000000000000000000100;
|
||||
const DefaultLane = /* */ 0b0000000000000000000000000010000;
|
||||
const TransitionLane1 = /* */ 0b0000000000000000000000001000000;
|
||||
const IdleLane = /* */ 0b0010000000000000000000000000000;
|
||||
const OffscreenLane = /* */ 0b0100000000000000000000000000000;
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
|
||||
- **과거 데이터와의 충돌:** 없음
|
||||
- **정책 변화:** 없음
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
function getHighestPriorityLane(lanes) {
|
||||
return lanes & -lanes; // isolate lowest set bit
|
||||
}
|
||||
function includesNonIdleWork(lanes) {
|
||||
return (lanes & ~IdleLanes) !== 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### startTransition (user code)
|
||||
```tsx
|
||||
import { startTransition, useState } from 'react';
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
const [tab, setTab] = useState('home');
|
||||
function select(next) {
|
||||
startTransition(() => setTab(next)); // → TransitionLane
|
||||
}
|
||||
```
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### useDeferredValue
|
||||
```tsx
|
||||
const [query, setQuery] = useState('');
|
||||
const deferred = useDeferredValue(query); // lower priority lane
|
||||
return <SearchResults q={deferred} />;
|
||||
```
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
### Lane assignment by event
|
||||
```javascript
|
||||
// React internal: getCurrentEventPriority()
|
||||
function eventPriorityFromEvent(eventName) {
|
||||
switch (eventName) {
|
||||
case 'click': case 'input': case 'submit':
|
||||
return DiscreteEventPriority; // → SyncLane
|
||||
case 'drag': case 'scroll': case 'mousemove':
|
||||
return ContinuousEventPriority; // → InputContinuousLane
|
||||
default:
|
||||
return DefaultEventPriority; // → DefaultLane
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### Render lane subset
|
||||
```javascript
|
||||
// performConcurrentWorkOnRoot (simplified)
|
||||
function renderRootConcurrent(root, lanes) {
|
||||
workInProgress = createWorkInProgress(root.current, null);
|
||||
workInProgressRootRenderLanes = lanes;
|
||||
while (workInProgress !== null && !shouldYield()) {
|
||||
performUnitOfWork(workInProgress);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
### Detect priority of update (debug)
|
||||
```javascript
|
||||
import { unstable_getCurrentPriorityLevel } from 'scheduler';
|
||||
console.log(unstable_getCurrentPriorityLevel());
|
||||
// 1 = Immediate, 2 = User-blocking, 3 = Normal, 4 = Low, 5 = Idle
|
||||
```
|
||||
|
||||
### Suspense retry lane
|
||||
```javascript
|
||||
// When boundary catches → throw to nearest Suspense → schedule retry on RetryLane
|
||||
// User code just renders <Suspense fallback={<Spin/>}><Lazy/></Suspense>
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Lane |
|
||||
|---|---|
|
||||
| 매 click / input | SyncLane |
|
||||
| 매 scroll / drag | InputContinuousLane |
|
||||
| 매 setState in effect | DefaultLane |
|
||||
| 매 startTransition | TransitionLane |
|
||||
| 매 Suspense retry | RetryLane |
|
||||
| 매 hidden subtree pre-render | OffscreenLane |
|
||||
| 매 background prefetch | IdleLane |
|
||||
|
||||
**기본값**: 매 React 가 매 자동 선택. 매 user 는 매 startTransition / useDeferredValue 만 매 명시.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[React]] · [[React Fiber]]
|
||||
- 변형: [[Expiration Time Model]] (legacy) · [[Scheduler]]
|
||||
- 응용: [[startTransition]] · [[useDeferredValue]] · [[Suspense]]
|
||||
- Adjacent: [[Concurrent Rendering]] · [[Time Slicing]] · [[OffscreenComponent]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 React internal 분석, 매 perf debug, 매 transition 설계.
|
||||
**언제 X**: 매 일반 product code — 매 자동 lane 선택 신뢰.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **모든 setState 를 startTransition**: 매 input 의 매 instant feedback 손실.
|
||||
- **useDeferredValue 의 매 너무 깊은 위치**: 매 메모이제이션 풀림.
|
||||
- **Lane 직접 조작 시도**: 매 unstable internal API.
|
||||
- **Sync 강제 (flushSync) 남발**: 매 concurrent 이점 무.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (React 18/19 source — `ReactFiberLane.js`, Andrew Clark 의 매 RFC).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — 매 lane bitmask + lifecycle |
|
||||
|
||||
Reference in New Issue
Block a user