Repository navigation
Performance sweep of basic functions: quadratic behaviour removed, O(1) array_shift, ~20 bugs fixed - #333
Merged
Conversation
…as raw IEEE bits (#298)
…m) (80k ints: 1.1 s -> 7 ms); add the basic-functions sweep probe
…Iterator foreach 1.7 s -> 0.8 ms at 20k) and O(n) php://memory append
…py per call (40k calls 12.7 ms -> 0.4 ms)
…as raw IEEE bits (Fixes #298)
…d instead of a strcmp chain (20k calls 22 ms -> 1.2 ms)
…ion lazily (2.2 us -> 0.34 us per call); pad year to 4 digits in Y and r
…tr_replace's worker binary-safe (substr_count 16x faster)
…n and mb_substr seek without a call per ASCII byte (mb_strlen+substr+upper 2.3 ms -> 0.05 ms at 20k)
…ve the count from lengths
…8x faster, php parity)
…sures (closure-bound array_search over ints 8.9 ms -> 0.06 ms); add the native assoc-sort primitive
…rt/krsort/asort/arsort (ksort 22.6 ms -> 3.3 ms at 20k)
…form ranks, trailing dots, overflow, ValueError on a bad operator (5k calls 5.0 ms -> 1.0 ms)
…-string arrays (ints 1.6 ms -> 0.7 ms at 20k)
…n (native hex check replaces a per-byte strspn)
…, cached POSIX-rule instants and last transition interval (3.1 us -> 1.4 us per strtotime)
…te skip, bound prune): 250x250 0.9 ms -> 0.28 ms
…ode when nothing escapes, scalar fast path in array_merge_recursive; match php for an empty separator and an empty parse_str name
…ipos in a loop 60x faster, str_ireplace native)
…on (str_word_count 30x faster)
…of byte-wise appends (strip_tags 2.5x faster)
…array (spread of $l[k][] arrays emptied the source, Fixes #309)
…ster on text without quotes)
… and length < 1 follow php 8.5
…ly compares it (Fixes #314)
…_split, reject negative array_fill count
…l column values kept (#319 filed for is_object on enum cases)
…arch, in-place compare, php ValueErrors
…all per comparison, parallel data/priority arrays
… and variadic functions callable by name (Fixes #317)
…es, no ' under HTML 4.01
… from body usage (Fixes #310)
…der, not by key (Fixes #313)
…s, ASCII icmp (func_str_dispatch 80k calls 9800 -> 430 us)
… channel; own the rebuild A bare `array` param specialized from its callers (vec[int], vec[string], ...) took stores of another element kind raw into the caller's typed buffer. The element scans now widen such a param (and a closure's by-value capture) to a cell element the way they widen a local literal: by-value is rebuilt at entry, by-ref is retyped and its callers follow. The entry rebuild is a new SELF_REBUILD ownership mode that drops the owned predecessor, so the converted copy no longer leaks its elements. Fixes #307, Fixes #259, Fixes #161
…nt meets a scalar parameter: it was invalid IR that broke the symfony-app build
…l gets: an object or array arrived as a raw word read as string bytes (#332, partly)
…mpiler rejects the param-aliasing form (bootstrap-from-pin)
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.
Summary
A sweep of ~150 basic string/array/SPL/date/regex functions at 20k and 80k inputs (
tools/bench/basic_fns_sweep.php, added here) for quadratic behaviour and for the gap to php 8.5, plus the bugs the sweep and its agents hit on the way. Quadratic first, slow-linear second, memory third.Quadratic behaviour removed
array_diff/array_intersect/*_keyArrayObject/ArrayIteratorforeach, element read of amixedpropertyfwritetophp://memory.=through astring &$sparameterarray_shift/array_unshiftloopstripos($s, $n, $offset)in a loopsimilar_texton periodic inputWhat is still quadratic is quadratic in php too (
array_mergein a loop,mb_substrin a loop, prepend, array by value,substr_replace).Slow-linear functions brought to php speed (selection)
in_array/array_search(7-95x),ksort/asort(native stable assoc sort),urlencode/urldecode,addslashes,substr_count,str_replacefamily,str_word_count,hex2bin,date()(10x),mb_*upper/lower/len,version_compare,levenshtein,ctype_*,html_entity_decode,array_fill,array_column,str_split,strtrwith an array,preg_*(in-place ovector, JIT, chunkedpreg_quote), SPL heaps, and calling a function by runtime name (22 us -> 5 ns per call with an inline cache).Final sweep: 109 of 151 cases within 1.2x of php, 87 faster; peak RSS never above php except
parse_str. Still >= 2x slower:base64(needs SIMD),nested_arr_read_modify,http_build_query,str_ireplace,ArrayObject,strtotime.Bugs fixed (found on the way)
Fixes #161 Fixes #209 Fixes #259 Fixes #283 Fixes #298 Fixes #300 Fixes #304 Fixes #305 Fixes #306 Fixes #307 Fixes #308 Fixes #309 Fixes #310 Fixes #311 Fixes #312 Fixes #313 Fixes #314 Fixes #315 Fixes #316 Fixes #317
Notable: a float passed to an
intparameter arrived as its raw IEEE bits (#298);array_merge(...$l)emptied the source's inner arrays (#309); a barearrayparameter written with another element type stored raw pointers (#307); numeric strings ordered as bytes by<andsort(#283, #308);array_shift/array_popleaked and kept destructors waiting (#314, #315).Partly fixed: #332 (by-name call of a stdlib function with an object argument no longer reads the pointer as string bytes; the TypeError mismatch of the lenient cell-to-string cast remains). New bugs found and filed, not fixed here: #319-#325, #329, #332.
Risk and what was run
array_shift/array_unshiftslide the array header (ARRAY_HEAD_GAP_OFFSET); every free / realloc site recovers the block start.docs/design/memory-abi.mdupdated.array_pop/array_shiftresults, builtin-argument element sharing,SELF_REBUILDstore mode, cell alias of a property read retained instead of cloned.bash tests/aot/run.sh -j 0= 2220 passed, 1 failed (async_socketpair_blocking_read, passes alone 3/3 - load flake), 2 skipped (no expected output);xfail.sh0 XPASS;symfony-console(15/22 invocations identical to Zend, the other 7 are 3 program-name artifacts and the known JSON/XML descriptor bugs symfony-console: list --format=xml segfaults in McXmlDoc::newNode #296 / symfony-console: JSON descriptor returns empty nested arrays (help) and crashes (list, help list) #297, same onmain);symfony-appbuilds, cold boot withoutvar/serves 200 / 404 in prod and dev, RSS flat over 600 requests.