"매 buffer 매 reuse 매 GC 의 X". Buffer allocation은 binary data buffer (ArrayBuffer / Typed Array)의 effective lifecycle 관리 — naive new Uint8Array(N) per operation은 GC churn을 유발해 frame budget을 깬다. 2026 WebGPU / WebCodecs / canvas heavy app 의 must-skill.
// main
constsab=newSharedArrayBuffer(1024);constview=newInt32Array(sab);worker.postMessage(sab);// worker — Atomics 매 lock-free synchronization
self.onmessage=(e)=>{constview=newInt32Array(e.data);Atomics.store(view,0,42);Atomics.notify(view,0,1);};
// 매 dev-only — 매 wrap allocator 매 trace
const_orig=Uint8Array;letcount=0;(globalThisasany).Uint8Array=function(...args: any[]){count++;if(count%1000===0)console.warn('Uint8Array allocations:',count);returnnew_orig(...args);};
매 결정 기준
상황
Approach
Per-frame temp buffer
pool with size class
Streaming binary protocol
preallocated parser buffer
Cross-thread share
SharedArrayBuffer + Atomics
GPU upload
persistent GPU buffer + map/unmap
Rare large alloc
direct allocate
기본값: measure GC pressure first; pool only when allocator shows up in profile.