Skip to content

perf(text-replace): share the optimised byte-replace across DSL and macho#295

Merged
indaco merged 3 commits intomainfrom
perf/share-replace-all
May 7, 2026
Merged

perf(text-replace): share the optimised byte-replace across DSL and macho#295
indaco merged 3 commits intomainfrom
perf/share-replace-all

Conversation

@indaco
Copy link
Copy Markdown
Owner

@indaco indaco commented May 7, 2026

Description

mt migrate rewrites and the macho patcher both walk large bodies of .la, pkgconfig, and dylib bytes. The patcher already routed its inner match loop through memchr-backed std.mem.indexOf / findPos after profiling showed mem.eqlBytes dominating the warm-ffmpeg samples. The DSL inreplace and DSL gsub builtins still ran a hand-rolled byte-eql loop on the same shape of input.

This PR collapses the three implementations into one shared replaceAll so every byte-replace in the codebase gets the fast path. The slow inner loop disappears from mt migrate post-install rewrites and from any formula that drives gsub over a large script body.

No public surface changes; no behavioural change beyond the algorithmic upgrade.

Related Issue

  • None

Notes for Reviewers

  • None

indaco added 3 commits May 7, 2026 20:16
…acho

The macho patcher's memchr-backed replaceAll, originally rewritten after
mem.eqlBytes dominated the warm-ffmpeg profile, now also drives DSL
inreplace and DSL gsub. Three hand-rolled byte-eql loops collapse into
one shared module, the slow paths in mt migrate post-install rewrites
disappear, and the release binary shrinks by ~16 KiB from the dedupe.
…afety paths

Tighten replaceAll's branch coverage: the prior set hit every multi-match
shape but skipped the count-equals-one short-circuit, the empty-input
guard, and the equal-length-replacement arithmetic. Also pin that an
expansion whose replacement contains the needle does not re-scan its own
output - a regression here would silently double-expand macho paths.
…ig shape

Cover what the inline tests can't reach: the result-allocation OOM path,
the no-alloc fast paths under a failing allocator, a 1000-match haystack
that drives findPos across memchr boundaries, and a synthetic pkgconfig
body shaped like the .pc / .la rewrites mt migrate runs through the DSL.
@indaco indaco merged commit ed41f3c into main May 7, 2026
3 checks passed
@indaco indaco deleted the perf/share-replace-all branch May 7, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant