"매 Scavenger 는 V8 의 minor GC — semi-space copying collector for short-lived objects". Cheney's algorithm 기반, young generation (new space) 을 from-space / to-space 로 나눠 매 minor GC 마다 live object 만 to-space 로 복사. Survivor 는 old space 로 promote. 매 fast (수 ms), 매 web app 의 hot path. Major GC (Mark-Sweep-Compact) 와 분리.
매 핵심
매 generational hypothesis
대부분 객체는 young 일 때 die → 매 young 만 자주 GC 하면 효율
V8 heap: new space (young, ~16MB) + old space (long-lived) + large object space + code/map space
매 Cheney's copying
new space = from-space + to-space (반반)
minor GC: from-space 의 live root → to-space 로 BFS-copy
매 dead object 은 자동 폐기 (sweep 불필요)
두번째 survival 시 old space 로 promote
매 비용
O(live data) — dead 가 많으면 매우 빠름
pause time: 매 1-5ms (web app)
write barrier: old → new pointer 추적 (remembered set)
import{writeHeapSnapshot}from"node:v8";constfile=writeHeapSnapshot();console.log(`매 snapshot at ${file}`);// load in DevTools → Memory tab → Compare snapshots
Avoid allocation in hot loop
// 매 BAD — 매 iteration creates objects
functionsumPoints(points:{x: number;y: number}[]):number{returnpoints.map((p)=>({...p,sum: p.x+p.y}))// new objects
.reduce((a,b)=>a+b.sum,0);}// 매 GOOD — 매 no allocation in loop
functionsumPointsFast(points:{x: number;y: number}[]):number{lets=0;for(leti=0;i<points.length;i++)s+=points[i].x+points[i].y;returns;}
언제: V8 GC 설명, Node.js memory tuning, hot-path optimization. 매 --trace-gc output 해석.
언제 X: 매 일반 web/app code review (premature opt 우려). 매 non-V8 runtime (Bun is JSC fork? actually JSCore — 다른 GC).
❌ 안티패턴
GC tuning premature: 매 measure 없이 flag 변경. 매 profile 먼저.
Manual global.gc(): 매 production 에서 --expose-gc 의존 — 매 anti-pattern.
Object literal in hot loop: GC pressure 증가. 매 reuse / pool.
Megamorphic shapes: 매 hidden class 변형 → IC miss → 추가 alloc. 매 shape 일정.
Closures in loop: 매 iteration 마다 closure 생성 → young heap pressure.
🧪 검증 / 중복
Verified (V8 blog, "Trash talk: the Orinoco garbage collector", 2016 + later updates).
신뢰도 A.
🕓 Changelog
날짜
변경
2026-05-08
Phase 1
2026-05-10
Manual cleanup — V8 Scavenger algorithm full content