Repository navigation
perf(js): String.eq compiles to === - #2075
Merged
Merged
Conversation
A String's JS text is canonical: char_new writes a scalar as itself and any other code as a lone \uDC00 marker and three units below 0x800, so equal Strings are equal texts. Base's String.eq walked both strings a character at a time (four slices and a Cmp per character); now it is one ===. C keeps Base's def. 2M comparisons of 17-character strings: 1.92 s -> 0.01 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On JS, Base's
String.eqwas compiled as written,Cmp.is_eq(String.order(a, b)): a loop that takes fourslices and allocates aCmpper character. It is now one===(a JS-only entry inOPERATIONS, likestring_append; C keeps Base's def).===is exact, not a fast path: a String's JS text is canonical.char_newwrites a Unicode scalar as itself and any other code as a lone\uDC00marker followed by three units below0x800, whichfromCodePointnever produces, and a String literal is only aLitwhen all its codes are scalars. So two Bend Strings are equal exactly when their JS texts are. (String.ordercannot use<the same way: UTF-16 order is not code-point order.)tests/base/string_eq.bend: empty, prefixes, astral chars, non-scalar codes (the marker form), surrogate pairs vs the astral char, built and sliced Strings vs literals; passes on interp, JS and C.String.eq/String.orderprint the same on JS;gates/repo.tspasses (comp.ts 65,977 -> 65,992 ttok).Context: #2038. Backplane writes string dispatch as
String.eqhelper chains because string-literal patterns blow up compilation (#1266); this makes that workaround fast at runtime.🤖 Generated with Claude Code