mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-21 05:50:55 +08:00
shift() moved every remaining element down one slot, making queue drains quadratic (100k elements: 0.85 s; 1M: no result in 30 s). Dense arrays of 8-byte slots with their own allocation now remove front elements by advancing data/present and lowering cap; the vacated slots stay in the allocation as head room. A flag in `spare` marks it and its size is implied by the layout (present == data + cap + head), so every reader, including inline element access in emitted code, is unchanged. Growth moves the elements back to the start of the allocation (in place only when that leaves half the moved count free, else geometrically), a drained array starts over at the front, unshift reuses head room, and an array unshift already had to move once reserves head room for half its length. scr_arr_outline drops head room before compiled storage swaps. Booleans, inline slots, sparse arrays and static arrays keep the old behavior. Scaling probes: shift/BFS/splice(0,1)/deque drains and unshift runs go from exponent ~2.0 to ~1.0 (shift 1e5 847 ms -> 1.6 ms); runtime bench geomean 1.0045 (neutral). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>