Repository navigation
Conversation
JS_ToQuotedString read and wrote one character at a time. Scan the run of code units that need no escape and append it with one string_buffer_write8/16; the code unit that ends the run takes the existing per-character path. The output is unchanged. On a 6 KB plain string this cuts the retired instructions of JSON.stringify by 81%, and by about half on chat-shaped JSON bodies (macOS arm64, Release build).
This branch has not been deployed
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.
JS_ToQuotedString(used for every string value and keyJSON.stringifywrites) reads and writes one character at a time (string_getc, aswitch,string_buffer_putc). Most characters in a JSON string need no escape.This scans the run of code units that need no escape (>= 0x20, not
", not\, and in a two-byte string not a surrogate) and appends it with a singlestring_buffer_write8/string_buffer_write16. The code unit that ends the run goes through the existing per-character path unchanged (escapes,\u00XXcontrols, surrogate pairs copied as is, lone surrogates as\udXXX), so the output is identical.Measured on macOS arm64 (Release build, retired instructions per
JSON.stringifycall):",\n,\\Test:
test_jsonintests/test_builtin.jsnow checks every code unit at the start, middle and end of a one-byte and a two-byte string, as a value and as a key, against QuoteJSONString written in plain JS.run-test262 -c tests.confgives the same result as onmasterin Release and Debug (here the only failure is the existingtest_std.js:254, which also fails without this change on macOS).