perf(stdune): use memchr for string searches - #16224
Open
rgrinberg wants to merge 6 commits into
Open
Conversation
rgrinberg
force-pushed
the
push-vkwnznnmtpvv
branch
2 times, most recently
from
August 28, 2026 09:26
79a2f51 to
522f55e
Compare
rgrinberg
force-pushed
the
push-vkwnznnmtpvv
branch
from
August 28, 2026 16:16
522f55e to
98634ae
Compare
rgrinberg
added a commit
that referenced
this pull request
Aug 28, 2026
Removes avoidable temporary allocations from frequently used string and path helpers. It adds option-free internal character searches, uses them in path decomposition, and constructs `Filename.concat` results in one pass. The dune-action-plugin path implementation now reuses the allocation-conscious `Stdune.Filename.concat`. This preparatory change was split from #16224 so allocation reductions can be reviewed independently from the C-backed search optimization. Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
rgrinberg
force-pushed
the
push-vkwnznnmtpvv
branch
3 times, most recently
from
August 28, 2026 16:52
a4945a6 to
4e6c0ff
Compare
Replace the pure unchecked forward string scan with a memchr primitive, use it for Stdune string searches, splitting, and validation, and generalize the spawn-specific NUL-byte search throughout Dune. Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
rgrinberg
force-pushed
the
push-vkwnznnmtpvv
branch
from
August 28, 2026 21:33
4e6c0ff to
1121bb9
Compare
Override the inherited scalar split_on_char implementation with Stdune.String.split so both public splitting APIs use the shared memchr-backed search. Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Skip long spans between ANSI escape sequences with the shared memchr-backed search while retaining a short OCaml scan for densely styled output. Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Skip spans without percent signs using the shared unchecked string search instead of examining every source byte in OCaml. Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Add a bounded memchr-backed Bytes search and use it to skip placeholder-free spans in the artifact substitution scanner. Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Scan Unix path components forward with the shared memchr primitive while retaining the multi-separator scanner on Windows. Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
rgrinberg
force-pushed
the
push-vkwnznnmtpvv
branch
from
August 28, 2026 21:44
1121bb9 to
9f6811c
Compare
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.
Generalizes the spawn-specific NUL search from #16117 into a reusable forward string-search primitive backed by
memchr.Stdune.Stringuses it for filename validation, splitting, spawn arguments, Unix path decomposition, and other forward character searches. Reverse searches and unrelated string transformations are deliberately left unchanged.Follow-up commits route sparse-delimiter parsers through the shared search, skip long spans while stripping ANSI escapes and scanning
dune substinputs, and add a bounded bytes search for the performance-sensitive artifact-substitution scanner. Lower-level standalone libraries that cannot depend on Stdune are also left unchanged.On ARM64 with OCaml 5.5, two alternating QEMU runs of a warm
@checkbuild counted 77.6M and 71.2M fewer user-space instructions, improvements of 1.08% and 0.99%. Thirty pairedperf statruns reduced median task CPU from 714.2 ms to 708.8 ms (0.74%, 18/30 pair wins).Representative focused measurements include:
dune subst: 264.6M to 56.6M QEMU instructions and 21.7 ms to 14.6 ms task CPU.Stdune.String.split_on_chardelegates toStdune.String.split, so both public splitting APIs consistently use the same implementation.