Skip to content

perf(js): check String.ends_with without reversing the inputs - #1646

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

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

Conversation

@oxura

@oxura oxura commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #1641.

JS no longer builds two reversed strings for a suffix check. The new intrinsic uses native endsWith, then checks that a matching suffix starts at a Bend Char boundary when U+DC00 occurs. The C implementation and checked Base definition stay unchanged.

A local exported-module probe uses 50,001 characters (ASCII plus an emoji):

Case Before After, warmed
Present suffix 5–7 ms 0.056–0.063 ms
Missing suffix 5–9 ms 0.053–0.081 ms
Empty suffix 5–9 ms 0.054–0.125 ms

Bun 1.3.13/Linux x86-64; whole API calls including host string handling, not a cross-platform benchmark. Boundary regressions cover ordinary text, empty and whole patterns, astral characters, packed payloads and a false UTF-16 match beginning inside an astral pair. AI-assisted.

@oxura

oxura commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

This is JS-only performance work, so I’m withdrawing it following the reference-runtime policy in #1644.

@oxura oxura closed this Oct 19, 2026
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.ends_with reverses the whole haystack even for a one-character or empty suffix

1 participant