Repository navigation
Typed SplFixedArray<Class> access and buffer foreach, const-list in_array chain, #159 - #166
Merged
Merged
Conversation
… instead of driving __McFixedArrayIterator A loop over Tokens ran at 20 ns per element through the iterator protocol (a boxed cell per step); the buffer loop is 4.4 ns. A subclass that overrides getIterator, and a by-reference foreach, keep the protocol path. Repro for the by-reference gap: #163.
… of compares instead of a loop over a heap vec php-cs-fixer's TokensAnalyzer::isBinaryOperator scans 30 token ids per token: 10 ns per call became 1 ns in isolation. An int list takes an int or a cell needle (guarded by is_int); a string list takes a string needle.
SplFixedArray is generic (@template T, offsetGet returns T), so `/** @extends SplFixedArray<Token> */ class Tokens` makes $tokens[$i] an obj<Token>: the emitter strips the cell word to the pointer, and the property read and the method call on it are direct instead of a name lookup on a cell. php-cs-fixer @psr12 over 276 files: 111.5G -> 103.6G retired instructions.
The foreach over a SplFixedArray bound to a class (`@extends SplFixedArray<Token>`) types its loop variable as that class: InferTypes sets Foreach_::$fixedBuf, the ownership pass binds the element's +1 as the class, and the emitter unboxes the cell word to the pointer.
…the string untouched; strrpos honours its offset
…placements skip expansion, no-match preg_replace returns the subject
…instead of throwing TypeError (#172)
…rray return type takes the +1 (Fixes #173)
…et-capture pairs as literals
This was referenced Oct 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Five compiler changes found while profiling a real application (a PHP-CS-Fixer fork, 276 files / 1.54M tokens). Together they take its
@PSR12run from 187G to 100G retired instructions with the application's own changes, of which the compiler share is the typedSplFixedArrayaccess and the bufferforeach(about 17%).SplFixedArrayis generic (@template T,offsetGetreturnsT)./** @extends SplFixedArray<Token> */ class Tokensmakes$tokens[$i]anobj<Token>: the emitter strips the cell word to the pointer, so the property read and the method call on it are direct instead of a name lookup on a cell.genericReturnTypenow starts from a class that has no parameters of its own but binds its parent's.foreachover a plainSplFixedArraywalks the native buffer like aVec(20 ns -> 4.4 ns per element). When the array is bound to a class the loop variable is that class too (Foreach_::$fixedBuf; inference, ownership and emitter agree on one condition). A subclass overridinggetIterator, a by-reference loop and a generator body keep the protocol path.in_arrayover a literal int or string list compiles to a chain of compares, which LLVM folds to a switch (10 ns -> 1 ns on a 30-id list). An int list also takes a?intneedle (guarded byis_int). Composes with perf(array): native scans for in_array and implode over typed vecs #162: the chain runs first, the native scan covers what it does not.static ??=cache of an array whose elements are a@phpstan-typealias crashed (SIGSEGV). The shape-field read typed an erased fieldunknown(a raw word) where an element read already sayscell.__preg_testin the stdlib: a does-it-match search that builds no$matches(3049 -> 1434 instructions on a one-line check). Nothing insrc/uses it yet.Not done here
foreachby reference over aSplFixedArrayiterates instead of throwing. Found on the way, repro included (tests/aot/repro/wrong/), unchanged by this PR.SplFixedArray<Class>that holdsnullin a slot gets a null pointer, not the cellnullit got before. Documented onunboxFixedElemObj; the typed use (Tokens) never has holes.Tests
New cases:
foreach_splfixedarray_native_loop,splfixedarray_bound_class_elements,splfixedarray_foreach_bound_class,in_array_strict_const_list,static_cache_phpstan_alias_elems(promoted from the #159 repro). AOT suite after rebasing ontomain: 1784 passed, 0 failed (2 skipped). Thein_arraycase checks semantics (it would also pass without the pass); that the chain is emitted shows indump-miras__mc_fuse_inarraylit_*.Bootstrap
No
src/code uses a feature of this change, soBOOTSTRAP_VERSIONis unaffected.Fixes #159