Repository navigation
perf(array): native scans for in_array and implode over typed vecs - #162
Merged
Merged
Conversation
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
in_arrayandimplodeover a statically typed vec went through generic paths: a synthesizedforeachwith a per-element retain/release and a__mir_str_eq_nscall chain for strings, and a per-elementsnprintfplus temporary string for floats. They now compile to runtime scans that read the element words directly. Also fixesbench/run.shon Linux.Changes
in_array, strict string instring[]—__mir_array_in_str. Compares pointer, then header length, then bytes; no retain/release of the element. A loose string search stays on the synthesized loop because"1e1" == "10"compares numerically.in_array,int/float/boolin a vec of the same kind —__mir_array_in_word. A raw packed buffer is swept eight words at a time with no branch inside the group; other buffer shapes use a one-element loop, unboxing each element by kind when the buffer is cellified. Floats compare as doubles (NANmatches nothing,0.0 == -0.0). Mixed types (e.g. an int needle in afloat[]) keep the synthesized loop.implodeovervec[float]—__mir_array_implode_float. A float whose%.14Gform is plain digits (integral or.5, below 1e13) is written straight into the result buffer; everything else goes through__mir_float_to_str, so the text is whatechoprints. A non-float buffer falls back to__mir_array_implode_cell.bench/run.sh— times cases without/usr/bin/time(falls back toEPOCHREALTIME/ perl) and prints-for RSS when the host cannot report it. Previously the awk expressions broke and the table showed no numbers on Linux. Addsbench/cases/in_array_int.php.The shape selection is shared:
InlineClosures::nativeScanShapedecides in both the lowering pass and the builtin emitter.Results
Linux x86_64, best of 3,
bench/run.sh:in_array(200-string vec, strict)implode_int(2000 ints + 2000 floats)in_array_int(1000-int vec)The
in_array_int"before" figure is from a separate run, not a direct A/B.Floats that are not integral or
.5(for example$i / 3) still format throughsnprintfand are not faster: 0.21 s against 0.18 s for php on the same case, output identical. A 14-significant-digit formatter would be the next step there.Tests
in_array_strict_str,in_array_scalar_vec,implode_float_vec. Each compares againstphpoutput (hit/miss, NUL bytes,NAN,-0.0,PHP_INT_MIN/MAX, hashed values afterunset,-0,INF,1.0E+25, buffer regrowth, mixed arrays).Not included
Object and enum elements (an enum element in a cell buffer is the case singleton, not an ordinal) and a hash index for repeated lookups on one array.