Skip to content

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

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

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.

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

1 participant