Repository navigation
Closed
Labels
Description
Problem
#92 delivers the native buffer runtime, SplFixedArray on it and the Manticore\Ds fixed-width typed arrays. Measured on the php-cs-fixer fork, swapping the storage under SplFixedArray gives about 3% CPU and 22% RSS: a faster container does not help a program whose hot data is still a cell per element. The containers have to cover more shapes of data, and the compiler has to remove the per-access cost that is left.
Proposal
Next parts of the Ds line, each small enough to ship alone, ordered by usefulness to real applications (first consumer: the php-cs-fixer fork). Status after PR #108 (merged 2026-10-07):
- php-cs-fixer fork on typed arrays — sandbox only, not a deliverable. A/B on the fork: about -3% CPU, -22% RSS;
SplFixedArraystorage is not the lever. No further work planned. - Growable typed vector — done. No separate class: every
Manticore\Ds\*Arrayhaspush(),pop()and$a[] = $v. 10M appends 600 ms → 27 ms (array51 ms). - Rest of SPL — done for
SplDoublyLinkedList/SplQueue/SplStack(O(1)shift, Zend LIFO/modes) andSplHeap/SplMinHeap/SplMaxHeap/SplPriorityQueue; both families fuzzed against php (5000 / 6000 rounds, no mismatch). Storage is a PHP list, not the native buffer (a cell buffer buys nothing there).ArrayObject/ArrayIteratorstay array-backed. Not emulated: mutating a list while a cursor is live, theSerializablemethods of the list,var_dumpof a heap subclass with own properties. - Access-cost leftovers — mostly done: length and handle loads hoisted out of counted loops, inline access for a receiver held in a property of a local or a static property (10M get/set: local
Int32Array5.4 ms, property-held 7.8 ms, was 168 ms). Loop versioning of the bounds compare is dropped: measured onInt32Array, a read-only loop is already guarded once and vectorised by LLVM, and a read-write loop is bound by the element range check (aValueErrorcontract), not by the bounds compare (2 of ~11 instructions per iteration).SplFixedArrayTBAA is dropped: measured 5.7 ns per$a[$i] = $a[$i] + $ion 1M elements, already below a PHParray(6.8 ns); its elements are cells, so the remaining cost is cell traffic, not the holder or length loads. Inline stores now also take bitwise values (& | ^ << >> ~; 16.7 → 0.12 ns per element onInt32Array). - Whole-array operations —
sum,min,max,equalsandapply(callable)(in-place map; 6.6 ns per element,array_map10.3) done. - Byte buffer and views —
ByteBufferwith endianness-aware typed reads/writes done. Views moved to Manticore\Ds: non-owning subarray views over a shared buffer #272 (no consumer: websocket/http useBuffer\ByteBuffer, a string + cursor). #[TypeDef(repr)]element types — done for scalar reprs (i8…u32,f32,f64): a typed array bound to a TypeDef class via docblock, with a width check on store. Enum-backed ints and packed structs moved to Manticore\Ds: #[TypeDef] element types for enum-backed ints and packed structs #273.UInt64Array— done. Typed string array moved to Manticore\Ds: typed string array on one byte buffer #271.- Polyfill package — generator exists (
php tools/ds_polyfill.php). Publishingmanticorephp/dsis dropped from this issue: a full polyfill is unlikely to be wanted, stubs are the probable shape, and superset features need not run under Zend.
Out of scope
Hash maps and sets with typed keys, persistent / immutable collections, concurrent containers. (Native Map / Set / Vec are tracked separately.)
Acceptance criteria
- Each part lands with cases that print the same bytes natively and under
phpwhere an oracle exists (SPL parts: plainphp; Ds classes have no Zend oracle). - Part 4: IR of a counted
Int32Arrayread loop has one length guard and no per-iteration bounds branch (LLVM hoists it); the write loop keeps the element range check by contract. -
docs/ds.mdcovers the new classes (UInt64Array,ByteBuffer,#[TypeDef]binding, polyfill). - Linux suite green for the ds / SplFixedArray cases (confirmed by CI).
Activity
blacktrs commentedon Oct 6, 2026
Progress on branch
ds-ownate894f8b9(not merged; macOS AOT suite 1684 passed / 0 failed; Linux not run):Manticore\Ds\*Arraygotpush(),pop()and$a[] = $v(this reverses theErroron[]from Native fixed-layout containers: SplFixedArray on a native buffer and Manticore\Ds typed arrays #92). The append is done in place while the buffer has room: 10M appends 600 ms → 27 ms (array51 ms).SplHeap,SplMinHeap,SplMaxHeap,SplPriorityQueuedid not exist; added with Zend's sift order, corruption protocol, dump and serialization.SplDoublyLinkedList/SplQueue/SplStackrewritten: O(1)shift/dequeue(wasarray_shift), LIFO offsets,add(), frozen stack / queue modes, a cursor that is invalid untilrewind(). Both families were fuzzed against php's own classes (5000 and 6000 random rounds: operations, exceptions,var_dump,print_r,serialize, iteration) with no mismatch. Storage is a PHP list, not the native buffer — a cell buffer buys nothing overlist<mixed>here.Not emulated: mutating a list while a cursor is live (php keeps a node pointer); the
Serializablemethodsserialize()/unserialize()of the list;var_dumpof a heap subclass with its own properties lists them after the heap internals.ArrayObject/ArrayIteratorstay array-backed by nature.Fixed in the compiler on the way:
var_dumpmarks protected / private properties;var_dump/print_rread a mangled__debugInfokey;__unserializereceives int keys as ints; a prelude file's own calls now pull in the array-function prelude (thearray_slice/array_spliceundefined-function trap behindSplQueue).Native containers: SplFixedArray on a native buffer, Manticore\Ds typ…
blacktrs commentedon Oct 16, 2026
Done in #108 and the follow-ups on main (apply, inline bitwise stores). Remaining parts split out: #271 typed string array, #272 views, #273 TypeDef enum/packed-struct. Bounds-check versioning, SplFixedArray TBAA and a published polyfill were measured or judged not worth doing; reasoning is in the issue body.