Crossing from 2,147,483,647 to 2,147,483,648 can change more than the numeric value: V8 moves from an SMI to a HeapNumber. HeapNumber is a heap-allocated object containing the number’s floating-point representation, with roughly 16 bytes for its header, double, and pointer. This allocation can create a performance and memory cliff in arithmetic-heavy code. section 3.4.2
V8’s simplified storage hierarchy follows these rules:
- Makes performance depend on engine version, CPU architecture, array size, cache behavior, optimization tier, and surrounding work. section 3.4.3
Keep monetary accumulation integral
Accumulating prices as decimal dollars turns the running total into HeapNumber values during the loop. Accumulating rounded cents keeps the total in the SMI-friendly integer path and converts to a decimal only at the end; the demonstrated integer approach can run at least twice as fast, though actual gains vary. section 3.4.3
