"매 Old generation 매 전체를 매 sweep 하는 매 비싼 GC cycle — 매 mark-sweep-compact 의 합성". 매 minor GC (Scavenge)와 대비되는 V8 의 second-tier collector — 매 long-lived object 의 final destination — 매 stop-the-world pause 의 가장 큰 원인.
매 핵심
매 단계
Mark: 매 root → reachable object tree-walk, mark bit set.
Sweep: 매 unmarked region 의 free list 추가.
Compact: 매 fragmentation 의 reduce 매 live object 매 좌측 이동.
constobs=newPerformanceObserver((list)=>{for(constentryoflist.getEntries()){if(entry.detail.kind===4)// 매 major GC
console.log('Major GC:',entry.duration,'ms');}});obs.observe({entryTypes:['gc']});
매 heap snapshot
constv8=require('v8');v8.writeHeapSnapshot('/tmp/snap.heapsnapshot');// 매 Chrome DevTools → Memory tab 매 load
매 incremental marking
node --trace-incremental-marking app.js
# 매 V8 매 mark phase 의 매 frame budget chunk 로 분할
매 max-old-space-size
node --max-old-space-size=4096 app.js # 매 4GB# 매 default 1.4GB on 64-bit
매 weak ref pattern
constcache=newMap();constref=newWeakRef(obj);// 매 GC 매 obj 의 collect 매 cache 의 자동 cleanup
constfinalizer=newFinalizationRegistry((key)=>cache.delete(key));
매 promotion threshold tune
node --min-semi-space-size=64 --max-semi-space-size=128 app.js
// 매 young gen 의 크기 의 키워서 promotion 의 줄임
매 chrome devtools profile
// 매 Performance tab → Record → 매 GC marker 의 yellow bar
// 매 매 marker 매 click → reason: "allocation failure" / "external memory"
매 결정 기준
상황
Approach
매 frequent major GC
매 heap profile + leak hunt
매 GC pause >100ms
--max-old-space-size 의 increase
매 promotion 폭발
--max-semi-space-size 의 increase
매 long-lived cache
WeakRef + FinalizationRegistry
기본값: 매 trace-gc 로그로 baseline → 매 profile 후 매 tune.