Repository navigation
perf(js): avoid rebuilding strings in String.contains - #1628
Merged
Lorenzobattistela merged 1 commit intoOct 16, 2026
Merged
Conversation
Lorenzobattistela
approved these changes
Oct 16, 2026
This was referenced Oct 17, 2026
nicolas-abril
added a commit
to nicolas-abril/bend
that referenced
this pull request
Oct 19, 2026
comp.ts keeps this branch's structure, with upstream's changes ported in: bendlang#1615's frame-slot write-back in bind_pop; bendlang#1617's named memo functions (open_of, spine_of, uses_of), per-file literal steps keyed by string, and lay_at memoized per type key (FL.ty_opens, keyed by ty_key); bendlang#1625's F32.read regex; bendlang#1628's string_contains. bendlang#1617's per-def PROBES reset is left out: here probes and the term caches live as long as the file and units emit again across sweeps, so a reset would reuse probe indices still held in FL.opens and FL.uses. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Merged
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.
String.contains rebuilds the remaining input before each prefix check. On the JavaScript backend, this makes even an absent one-character search quadratic. A local search for
"b"in 1,024,000"a"characters took 7,209 ms.Add a JS intrinsic that checks prefixes at Bend Char boundaries and advances an index through the original string. Reuse
char_lenwith an optional offset. This preserves arbitrary U32 Char codes and prevents matches inside their packed representation. Base definitions and their proof reductions stay unchanged.On Apple M5 Max with Bun 1.3.14, the same search took 5.45 ms with the change. Both figures are medians of three calls; they exclude input creation and compiler startup. This removes suffix reconstruction, but repeated long prefixes can still require O(N*M) comparisons.
Add two Bend regressions: character and partial-application cases with an unfolding proof, and a two-million-character absent search under the existing test gate timeout.
Validation: