Skip to content

JS String.contains still scans ordinary text character by character #1637

Closed

Description

@oxura

The packed-Char boundary handling in #1628 is needed, but every ordinary string still takes the per-character startsWith loop. On main e5527d5, a real exported Bend contains(s: String, p: String) -> Bool takes 77-79 ms to reject a 1024-character almost-matching needle in one million ASCII characters (Bun 1.3.13, Linux x86-64). The UTF-16 packed-Char sentinel is U+DC00. When the haystack contains no such code unit, native includes can search without a false match inside a packed Char. I am testing that fast path while retaining the existing boundary walk whenever the sentinel occurs, including an astral pair containing U+DC00. This does not change the String API or the behavior of non-scalar Chars.

Activity

  1. Lorenzobattistela commented on Oct 19, 2026

    @Lorenzobattistela
    Collaborator

    Closing with #1644. This is a JS-only performance request with no wrong output, and the JS backend is the reference runtime: we keep it simple rather than add special cases for speed. Performance work goes to the C runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions