Validate JSON scalars in place instead of materializing byte lists#8
Closed
ESRogs wants to merge 1 commit into
Closed
Validate JSON scalars in place instead of materializing byte lists#8ESRogs wants to merge 1 commit into
ESRogs wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ESRogs
force-pushed
the
json-string-str-walk
branch
from
July 18, 2026 17:18
76176b7 to
e370d74
Compare
ESRogs
force-pushed
the
json-scalar-validators-str-walk
branch
from
July 18, 2026 17:18
dd6bcb2 to
6b6ae76
Compare
Owner
Author
|
Combined with #5 and opened upstream as roc-lang#10217 (branch |
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.
Important
Stacked on #5 (which sits on roc-lang#10173, which sits on roc-lang#10145). Merge in that order.
Overview
Completes the removal of
Str→List(U8)conversions from the JSON parse path. roc-lang#10173 converted whitespace trimming and scalar splitting; #5 converted string scanning and decoding; this PR converts the remaining four scalar/Dec helpers —is_json_number,json_dec_digits_are_zero,trim_json_dec_leading_zeros, andnormalize_json_dec_digits. After it, the JSON parse path contains noStr.to_utf8at all.Detail
is_json_numberwalks the scalar's bytes in place:count_utf8_bytes+str_get_utf8_byte_unsafereplace theto_utf8List andlist_get_unsafereads; the grammar walk is otherwise unchanged.json_dec_digits_are_zeroiterates lazily withfor byte in Str.iter_utf8(digits).trim_json_dec_leading_zeroscounts leading zeros in place and takes the remainder withstr_drop_first_bytes_unsafe— the dropped prefix is ASCII zeros, so the cut is a proven UTF-8 boundary (previously this revalidated the tail throughfrom_utf8_lossy).normalize_json_dec_digitssplits the digit string withstr_substring_unsafe/str_drop_first_bytes_unsafeat a digit boundary instead of twofrom_utf8_lossyreconstructions.Allocation coverage
check_json_parse_allocs!intest/alloc-count/app.rocgains a skipped-numeric-field case on a small (SSO) document. On the base branch it fails with exactly one allocation (is_json_number'sto_utf8copy of the SSO scalar slice); with this PR the whole parse is zero allocations.Benchmarks
Interleaved against the base branch (#5's tip; median wall time for a loop of 20,000
Json.parsecalls decoding{ k0 : Str }, default LLVM--opt=speed, macOS arm64):is_json_number)The modest delta is expected:
to_utf8on a slice of a heap-backed document was already zero-copy, so the win is the List wrapper and refcount traffic, plus the SSO allocation above.Testing
JsonScalarParseEdgeCases(51),JsonEncodeNumberEdgeCases(13),JsonStringEscapes(64) all pass; the alloc-count platform app passes on the dev backend and--opt=speedincluding the new check.