Repository navigation
Performance sweep of string and array functions, with the bugs it found - #274
Merged
Merged
Conversation
…KB: 77 us -> 1.9 us)
2 tasks
…: 528 ms -> 0.95 ms)
…cal: fixes double release of a captured array on mutation (Fixes #275)
…cwords in-place (20.7 -> 1.3 ns/B), nl2br chunked appends (13.1 -> 3.3 ns/B)
…umeric needle (typed 40 -> 3.3 ns/el, erased 40 -> 10 ns/el)
…okup tables; base64_decode follows php's loose/strict rules (20 KB: b64 enc 134 us -> 11 us, dec 167 us -> 27 us, bin2hex 312 us -> 15 us, hex2bin 213 us -> 13 us)
… candidate first bytes with strcspn (20 KB: 3-arg 50 us -> 7 us, array 116 us -> 30 us)
…t: 14/10.5/7.8 -> 0.4/1.0/1.0 ns/el; php 2-3); raw scalar element lists skip the retain/release walk
…d or non-hex input, an empty pad or bad pad type, an empty strtr key (Fixes #281)
…em; objects, references and enums fall back to the PHP walker (list of 2000 strings 3.3 -> 0.47 ns/B, ints 4.6 -> 1.1, assoc 5.4 -> 1.7, nested 6.0 -> 0.9; php 0.56 / 1.26 / 3.95 / 1.8) (#280)
…0 ns/el; php 1.1)
…he PHP parser keeps objects, r:/R:, enums and every error path (list of 2000 strings 6.6 -> 1.7 ns/B, ints 9.1 -> 1.0, assoc 11.3 -> 3.4, nested 14.6 -> 2.9; php 0.85 / 1.8 / 3.2 / 1.9); serialize_codec test; 'i:;' is an error (#280)
…s 780 -> 83 ns/el sorted-ish; php 160; shuffled cell strings 1015 -> 262, php 151)
…ted by the element hint the static type implies (closure and nested-array lists stay on the loop, no extra return type); int lists 14/10.5/7.8 -> 0.3/0.2/0.2 ns/el, php 2-3
# Conflicts: # src/Compile/Mir/Passes/InferCalls.php
# Conflicts: # src/Compile/Mir/Ownership.php # src/Compile/Mir/Passes/EmitLlvmBuiltins.php # src/Compile/Mir/Passes/LowerFns.php
blacktrs
added a commit
that referenced
this pull request
Oct 16, 2026
….0 (#294) * Add repros for ReflectionParameter default values missing for trait, interface and prelude methods (#287, #288) * Synthesize parameter-default factories for trait, interface and prelude methods, in the declaring class scope. Fixes #287 Fixes #288 * Resolve class constants through every extended interface, not only the first (Fixes #287, Fixes #288 end-to-end: symfony-app dev boots) * Add repro for ReflectionProperty::setValue on prelude-class properties (#289) * Rebind a closure held in an erased receiver via bindTo instead of routing it through an unrelated __call (Fixes #290) * Release 0.15.0 * Re-baseline dump-llvm goldens drifted by #274 (stdlib sig change) * Give throwable properties reflection accessors and report readonly setValue as Error (Fixes #289) * Recapture CLI behaviour golden after the prelude IR change * Add repros for method calls on erased receivers routed to an unrelated __call (#292, #293) * Make the CLI golden test codegen-independent * Run tests/cli in CI * Remove the weekly gate.yml workflow; difftest is a manual staleness check
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
Performance sweep over the standard string and array functions, plus the bugs the sweep turned up. The sweep measured ~40 functions at 20 000 and 80 000 byte inputs (native vs php 8.5); everything was linear except
array_unique, and a dozen were 5-150x slower than php (tracking issue #278).Speed (arm64 macOS, native, before -> after; php in brackets)
str_repeat(64 KB, 4-byte pattern)array_unique(10 000 strings)strrev(64 KB)ucwords/nl2br/trimbase64_encode/decode(20 KB)bin2hex/hex2binstr_pad/strtrarray formserialize/unserialize(2000 strings)in_arraymiss, typed stringsarray_slice/array_reverse/array_merge(int list)rangesort10k strings, near-sortedapplyMaskinprelude/websocket.php(64 KB)How:
str_repeatcopies by doubling instead of onememcpyper repetition (this was the whole cost of the websocket mask);array_uniquekeeps a seen-set;strrev, base64/hex, serialize/unserialize and the list copies are native IR routines, each shipped with a same-named PHP body per the bootstrap rule;sortis a native stable merge sort for int and string lists.Bugs fixed
$l[] = 1,array_pop($l),array_shift($l)) was released twice at exit and aborted on large arrays. The body now works on a local copy that owns its count. Merged with the narrower fix already on main (arrayHintedfor captures of array params).addslashesstopped at the first NUL byte; it is binary safe now and escapes NUL as\0.hex2bin(odd or non-hex input),str_pad(empty pad, bad pad type) andstrtr(empty key) throwValueErrorwhere php rejects or warns.base64_decodefollows php's loose and strict rules (it used to stop at the first=and treat\v/\fas whitespace).trim/ltrim/rtrimaccepta..zranges in the mask.Left open (filed)
array_flipandarray_splice(#285),sortof numeric strings (#283),rangeof numeric-string endpoints (#284),unserializeaccepting malformed floats (#282). Each has a repro undertests/aot/repro.Tests
One case per function with sizes around the word and block boundaries (0, 1, 7, 8, 9, 15, 16, 17, 100, 4097), high bytes and NUL, expected output from
php. Run filtered: closure (91), str_repeat, array_unique, strrev, ucwords, nl2br, trim, addslashes, base64, hex, str_pad, strtr, string_arg, in_array, array_bulk, range, sort_native, serialize: all pass on macOS arm64. Also built from the pinned release alone (bin/buildwith nobin/manticore) before the merge with main, then rebuilt after it.Not run: the whole AOT suite, difftest, the Linux gate,
selfhost_fixpoint.sh.Review notes
strtrbyte form: main and this branch each added a native version; main's (no allocation when nothing translates) is kept.src/edits worth a look:reprOrHintIrinUnifiedArrayRuntime.php(skips the element walk for raw int/float/bool hints) and the loose string compare inInlineClosures.php.