Client Runtime & Memory Spec

What is an In-Memory Ring Buffer? Zero-GC Telemetry Aggregation

Why allocating `{ x, y, t }` JavaScript objects at 120Hz thrashes V8's nursery heap, and how fixed-width `Float32Array` circular ring buffers keep memory flat.

Direct Definition

A RAM Buffer Pipeline is a client-side memory management architecture that writes high-frequency pointer, scroll, and touch samples into a pre-allocated circular `ArrayBuffer` (ring buffer) in volatile RAM, downsampling and batch-serializing kinetic windows before dispatching network frames.

Why Naive Object Arrays Fail at 120Hz Sampling Rates

Drag a finger across an iPhone ProMotion display or a 120Hz Android flagship and the browser dispatches a `pointermove` event every 8.33 milliseconds. If a telemetry handler pushes a fresh `{ x, y, velocity, timestamp }` JavaScript object onto a standard dynamic array on every sample, it allocates 120 heap objects per second - 7,200 objects per minute of active browsing.

Every one of those transient objects lives in V8's Young Generation (Nursery) heap. Once the nursery fills, the engine halts JavaScript execution to run a Scavenger minor garbage collection sweep. Worse yet, firing an HTTP request per raw event saturates the browser's six-connection-per-origin HTTP/1.1 pool (or multiplexes hundreds of tiny HTTP/2 frames), keeping the mobile cellular radio pinned in its high-power `DCH` state. Naive `lodash.throttle` wrappers "solve" this by dropping 90% of samples - which blinds downstream classifiers to sudden velocity inflections.

Contiguous Memory Layout of a Typed Ring Buffer

Instead of allocating dynamic objects or discarding intermediate samples, our Zero DOM-Blocking Predictive Intent runtime reserves a single contiguous 16 kB `ArrayBuffer` at boot time. A `Float32Array` view partitions that slab into 1,024 fixed 16-byte slots (4 floats per sample):

Byte Offset TypedView Field Data Representation Memory & GC Behavior
0x00 – 0x03 Float32[i + 0] Normalized viewport X coordinate ($0.0 \dots 1.0$) In-place overwrite; 0 heap allocations
0x04 – 0x07 Float32[i + 1] Normalized viewport Y coordinate ($0.0 \dots 1.0$) In-place overwrite; 0 heap allocations
0x08 – 0x0B Float32[i + 2] Monotonic delta $\Delta t$ (`performance.now()` ms) Sub-millisecond precision preserved
0x0C – 0x0F Float32[i + 3] Event type & pointer bitmask (`touch` | `mouse` | `wheel`) Bit-packed scalar; cache-line aligned

Bitwise Ring Wrapping & Lifecycle Flush Mechanics

Choosing a power-of-two capacity ($2^{10} = 1024$ slots) lets the write cursor wrap around the end of the buffer using a single bitwise AND instruction (`cursor & 1023`) instead of a slower modulo division. Every 300ms - or immediately when a `visibilitychange` to `hidden` fires - the pipeline computes summary kinematics across the active slice and hands the compact payload to our CORS Preflight Bypass transport or terminal Keepalive and sendBeacon() dispatcher:

const SLOT_COUNT = 1024; // Must be power of 2 for bitwise mask
const MASK = SLOT_COUNT - 1;
const STRIDE = 4;

// Single 16,384-byte allocation for the entire lifetime of the tab const slab = new ArrayBuffer(SLOT_COUNT * STRIDE * Float32Array.BYTES_PER_ELEMENT); const ring = new Float32Array(slab); let head = 0; let tail = 0;

export function writeSample(normX, normY, dt, kindMask) { const base = (head & MASK) * STRIDE; ring[base] = normX; ring[base + 1] = normY; ring[base + 2] = dt; ring[base + 3] = kindMask; head = (head + 1) | 0;

// If buffer is full before network flush, advance tail (overwrite oldest) if (head - tail > SLOT_COUNT) { tail = head - SLOT_COUNT; } }

If a mobile user drops into a subway tunnel and loses connectivity for twenty seconds, the ring buffer never grows unbounded. Once `head - tail` reaches 1,024 samples, the write pointer overwrites the oldest stale coordinates in place, guaranteeing that client RAM consumption never exceeds its 16 kB allocation.

Memory & Transport Spec // 16 kB Fixed Slab

Zero Heap Churn. Zero Unbounded Buffers.

Examine our client-to-edge transport specification to see how typed ring buffers and single-RTT edge ingestion stream 120Hz kinematics without touching V8 GC.