docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
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 폴더 제거.
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
---
|
||||
id: wiki-2026-0508-v8-엔진-힙-아키텍처
|
||||
title: V8 엔진 힙 아키텍처
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [V8 Heap Architecture, V8 메모리 관리, Orinoco, V8 GC]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [v8, javascript, gc, memory-management, runtime]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: C++/JavaScript
|
||||
framework: V8 (Chrome/Node.js)
|
||||
---
|
||||
|
||||
# V8 엔진 힙 아키텍처
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 generational + concurrent + parallel + incremental GC — Young (Scavenger) + Old (Mark-Sweep-Compact) + Orinoco pipeline 으로 매 main-thread pause 의 ms 단위로 압축"**. 매 Google V8 (Chrome/Node.js/Deno/Edge) 의 메모리 관리. 매 Orinoco (2016~) 프로젝트 의 GC 의 90%+ off-main-thread. 매 2026 의 V8 12.x 의 production state.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Heap 구조
|
||||
- **New Space (Young Generation)**: 매 1-8MB. 매 short-lived objects. 매 Scavenger (Cheney's copying) 으로 collect.
|
||||
- From-space + To-space (semi-space). 매 alloc 의 from-space pointer bump.
|
||||
- Scavenge: live objects 의 to-space 로 copy → swap. 매 두 번 survive 한 object 는 Old Space 로 promote.
|
||||
- **Old Space**: 매 long-lived objects. 매 Mark-Sweep-Compact 으로 collect. 매 Major GC.
|
||||
- **Large Object Space**: 매 ≥256KB objects (large arrays, strings). 매 직접 alloc, no copy.
|
||||
- **Code Space**: 매 JIT-compiled code (TurboFan, Maglev, Sparkplug).
|
||||
- **Map Space**: 매 hidden classes (V8 Maps) — object shape descriptors.
|
||||
- **Read-Only Space**: 매 immutable singletons (true, false, null, undefined).
|
||||
|
||||
### 매 Orinoco (modern GC pipeline)
|
||||
- **Concurrent Marking**: 매 main-thread alongside 의 worker threads 의 mark phase 실행. Tri-color invariant (white/grey/black) + write barrier 로 mutator 와 coexist.
|
||||
- **Parallel Sweeping/Compacting**: 매 multiple GC threads 의 simultaneously work.
|
||||
- **Incremental Marking**: 매 marking 의 small chunks 로 split — 매 main thread pause 의 <1ms 로 amortize.
|
||||
- **Lazy Sweeping**: 매 sweep 의 alloc time 의 on-demand.
|
||||
|
||||
### 매 Hidden Classes + Inline Caches
|
||||
- 매 V8 의 dynamic JS object 의 internally fixed-shape "Hidden Class" 로 represent — 매 property access 의 C++ struct field access 만큼 fast.
|
||||
- 매 IC (Inline Cache) 가 call site 에서 매 last shape 의 cache → 매 monomorphic 의 fast path.
|
||||
|
||||
### 매 응용
|
||||
1. Node.js backend 의 메모리 leak 의 debugging — heap snapshot, retainer chain.
|
||||
2. Browser tab memory budget 관리 — Chrome DevTools Memory tab.
|
||||
3. Server-side rendering 의 short-lived object 의 polymorphism 회피로 throughput 증가.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Heap snapshot in Node.js
|
||||
```javascript
|
||||
const v8 = require('v8');
|
||||
const fs = require('fs');
|
||||
|
||||
// Trigger heap snapshot
|
||||
const stream = v8.getHeapSnapshot();
|
||||
const file = fs.createWriteStream(`heap-${Date.now()}.heapsnapshot`);
|
||||
stream.pipe(file);
|
||||
// Open in Chrome DevTools → Memory → Load
|
||||
```
|
||||
|
||||
### Heap statistics
|
||||
```javascript
|
||||
const v8 = require('v8');
|
||||
console.log(v8.getHeapStatistics());
|
||||
// { total_heap_size, used_heap_size, heap_size_limit, ... }
|
||||
|
||||
console.log(v8.getHeapSpaceStatistics());
|
||||
// per-space: new_space, old_space, code_space, large_object_space, ...
|
||||
```
|
||||
|
||||
### Force GC (debug only)
|
||||
```bash
|
||||
node --expose-gc app.js
|
||||
```
|
||||
```javascript
|
||||
if (global.gc) {
|
||||
global.gc();
|
||||
console.log(process.memoryUsage());
|
||||
}
|
||||
```
|
||||
|
||||
### Tune heap size (production Node.js)
|
||||
```bash
|
||||
# 4GB old space
|
||||
node --max-old-space-size=4096 server.js
|
||||
|
||||
# 64MB young space (default ~16MB)
|
||||
node --max-semi-space-size=64 server.js
|
||||
```
|
||||
|
||||
### Avoid hidden-class transitions (perf pattern)
|
||||
```javascript
|
||||
// Bad — hidden class transitions
|
||||
const u1 = {};
|
||||
u1.name = 'a'; u1.age = 1; // shape A → B
|
||||
const u2 = {};
|
||||
u2.age = 1; u2.name = 'a'; // different shape! (order matters)
|
||||
|
||||
// Good — same shape every time
|
||||
function makeUser(name, age) {
|
||||
return { name, age }; // same hidden class
|
||||
}
|
||||
```
|
||||
|
||||
### Heap profiling (allocation sampling)
|
||||
```javascript
|
||||
const inspector = require('inspector');
|
||||
const session = new inspector.Session();
|
||||
session.connect();
|
||||
|
||||
session.post('HeapProfiler.startSampling');
|
||||
// run workload
|
||||
session.post('HeapProfiler.stopSampling', (err, { profile }) => {
|
||||
fs.writeFileSync('profile.heapprofile', JSON.stringify(profile));
|
||||
});
|
||||
```
|
||||
|
||||
### Detect memory leak (retainer)
|
||||
```javascript
|
||||
// Common leak: closure holding large object
|
||||
const cache = new Map();
|
||||
function handler(req) {
|
||||
const huge = loadHuge();
|
||||
cache.set(req.id, () => huge.someMethod()); // closure pins huge
|
||||
}
|
||||
|
||||
// Fix: WeakRef + WeakMap (2026 standard)
|
||||
const cache2 = new WeakMap();
|
||||
function handler2(req) {
|
||||
cache2.set(req, loadHuge()); // GC eligible when req dies
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Action |
|
||||
|---|---|
|
||||
| Node.js OOM (heap limit) | `--max-old-space-size` 증가 + heap snapshot 분석 |
|
||||
| 매 잦은 short-lived object → Major GC pressure | Young space 증가 (`--max-semi-space-size`) |
|
||||
| 매 polymorphic call site (slow) | Object shape 의 stabilize — 매 same constructor + same property order |
|
||||
| 매 Large array (>256KB) | Large Object Space 로 직접 — 매 copy 의 X |
|
||||
| 매 long-running process leak | Heap snapshot + retainer chain — 매 closure / event listener / global Map |
|
||||
|
||||
**기본값**: Production 의 매 `--max-old-space-size=4096` + heap snapshot 의 weekly capture.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Garbage Collection]]
|
||||
- 변형: [[Mark-Sweep-Compact]]
|
||||
- 응용: [[Node.js Memory Tuning]] · [[Chrome DevTools Memory]]
|
||||
- Adjacent: [[Inline Cache]] · [[JIT Compilation]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 Node.js memory leak 분석 (heap snapshot retainer), 매 V8 GC tuning flag 추천, 매 hidden class transition 의 detect 및 fix, 매 GC pause 분석 (`--trace-gc`).
|
||||
**언제 X**: 매 다른 JS engine (JSC/SpiderMonkey/Hermes) — 매 다른 GC architecture.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **잦은 `delete`**: 매 hidden class transition trigger → polymorphic IC. 매 `obj.x = undefined` 도 같은 문제. 매 missing values 의 `null` 로 init from start.
|
||||
- **Megamorphic call sites**: 매 4+ shapes 의 같은 call site 의 hit → IC 의 megamorphic fallback (slow path).
|
||||
- **거대 closure**: 매 closure 의 enclosing scope 의 모든 var 의 keep alive — 매 small subset 만 capture (let inside).
|
||||
- **`--max-old-space-size` 의 무한 증가**: 매 leak 의 mask — 매 root cause 의 fix.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (V8 공식 blog v8.dev — Orinoco/Sparkplug/Maglev 시리즈, Node.js docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full V8 heap architecture canonical with Orinoco pipeline and 7 patterns |
|
||||
Reference in New Issue
Block a user