You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JS String.length allocates an array proportional to the whole string #1612
The JS String.length intrinsic expands the whole string with [...str_out(s)] just to count its characters. That adds O(n) temporary storage, including a second representation of every supplementary Unicode character.
I compiled this real Bend consumer on 7e120d5:
importBasedefpayload() ->IO(String):
import"./payload.js"defmain() ->IO(Unit):
doIO<Unit>:
s : String<-payload()
IO.print(Nat.show(String.length(s)))
It correctly prints 2000000, but three fresh Bun processes peak at 170988, 171744 and 170592 KiB RSS (/usr/bin/time -f %M bun program.js). The payload itself is four million UTF-16 code units; counting it should not require a two-million-element array. Current main keeps the same intrinsic.
The existing internal Char-width decoder can walk the string with an offset and a counter, preserving arbitrary U32 Chars as well as Unicode scalars without text-edge conversion. I am checking that change against the existing Char/string regressions and the same payload. AI-assisted investigation.
Activity