Skip to content

perf(js): count String characters without materializing an array - #1614

Closed
oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/js-string-length-space-20261016
Closed

oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/js-string-length-space-20261016

Conversation

@oxura

@oxura oxura commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #1612.

Counting a String no longer expands it into a character array or converts its non-scalar Chars at a text edge. The loop walks the existing internal Char widths; the head/tail decoder now accepts an offset, and both existing call sites pass zero. Extra counting storage changes from O(n) to O(1).

I compiled the same Bend program returning two million emoji, then measured three fresh Bun processes per build with /usr/bin/time -f %M. Every run printed 2000000. These are whole-process peak RSS medians, not an allocation-profiler estimate:

build median peak RSS (KiB)
before 170988
after 56092

The mixed ASCII/astral/arbitrary-U32 regression, string_kit, char_any_code and string_unicode all pass on Bun and native C. Repo gate: 54/54.

Based on 7e120d5; compiler size is 63,618 → 63,696 (+78). I left this draft alongside #1606/#1610 while main remains at 64,092 against the permanent 64,000 cap. No cap changes, comment trimming or new dependencies.

Linux x86-64, Bun 1.4.3, clang 22.1.8; the mini-cluster/Metal/CUDA gates were not run here. AI-assisted patch.

@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.

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.length allocates an array proportional to the whole string

1 participant