Skip to content

perf(js): use native search when String.contains needs no packed-Char walk - #1644

Closed
oxura wants to merge 2 commits into
bendlang:mainfrom
oxura:perf/js-string-contains-20261017
Closed

oxura wants to merge 2 commits into
bendlang:mainfrom
oxura:perf/js-string-contains-20261017

Conversation

@oxura

@oxura oxura commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #1637.

Keep #1628's boundary walk when a haystack contains U+DC00. Otherwise native substring search is safe: there cannot be a match inside a packed U32 Char. An astral pair containing U+DC00 conservatively keeps the existing path.

Measured through an actual exported Bend function on Bun 1.3.13/Linux, rejecting a 1024-character almost-match in one million ASCII characters:

Call Before After
String.contains 77–79 ms 0.30–0.37 ms

Added consumer regressions for ordinary text, empty patterns, astral characters, a match inside a packed payload, a false UTF-16 match across an astral boundary, and a genuine match after a packed Char. Generated C and JS print all seven expected answers. Repository gate: 54/54. Mini-cluster/Metal/CUDA not run. AI-assisted.

@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

Thanks for the careful work and the measurements. We're closing this one: the JS backend is Bend's reference runtime, and we don't want ad-hoc performance special cases there. Performance work belongs on the C side. #1628's boundary walk is the behavior we want to keep in JS.

Separately, guide/GUIDE.md is written by hand. Please leave it out of PRs, including rewording to make room for new lines.

@oxura

oxura commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Got it — I’ll leave GUIDE.md alone and keep performance changes on the C side. Thanks for spelling that out.

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.

JS String.contains still scans ordinary text character by character

2 participants