perf(text-replace): share the optimised byte-replace across DSL and macho#295
Merged
perf(text-replace): share the optimised byte-replace across DSL and macho#295
Conversation
…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.
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.
Description
mt migraterewrites and the macho patcher both walk large bodies of.la, pkgconfig, and dylib bytes. The patcher already routed its inner match loop through memchr-backedstd.mem.indexOf/findPosafter profiling showedmem.eqlBytesdominating the warm-ffmpeg samples. The DSLinreplaceand DSLgsubbuiltins still ran a hand-rolled byte-eql loop on the same shape of input.This PR collapses the three implementations into one shared
replaceAllso every byte-replace in the codebase gets the fast path. The slow inner loop disappears frommt migratepost-install rewrites and from any formula that drivesgsubover a large script body.No public surface changes; no behavioural change beyond the algorithmic upgrade.
Related Issue
Notes for Reviewers