perf: optimize JSON struct deserialization - #213
Open
JairusSW wants to merge 3 commits into
Open
Conversation
JairusSW
marked this pull request as ready for review
July 24, 2026 04:29
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.
What changed
CONTEXT.mdWhy
The existing reuse trace path recorded every string and object field even when consecutive requests used different source strings. Those traces could never produce a cache hit.
For fresh materialization, long UTF-16 string scans handled only eight code units per vector, and fresh GeoJSON coordinate pairs missed the existing two-slot fast path. Each pair also reserved six unused numeric slots; Canada contains 55,563 coordinate pairs, making that allocator overhead the largest remaining hot-path cost.
Impact
Reuse latency improvements from the trace-admission change remain approximately:
Against
json-parser-benchmarks, the fresh-materialization changes now measure approximately:The comparison remains below json-ty's 816 MB/s geometric mean. The remaining gap is dominated by representation/allocation differences: json-as constructs managed AssemblyScript strings and nested arrays, while json-ty parses raw UTF-8 into a compact releasable document representation.
The exact-capacity coordinate buffers also materially reduce heap pressure. On the memory-instrumented fresh Canada minified benchmark, peak Wasm memory fell from 316 MiB to 158 MiB and in-flight live memory fell from about 74.7 MiB to 11.2 MiB. Post-GC retention remains stable.
Validation