perf(json): presize maps during FromJson decode - #4139
Open
mizchi wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Improve @json.FromJson decoding performance for Map[String, V] by pre-sizing the destination map based on the input JSON object size, and add targeted native-release benchmarks to track regressions/improvements.
Changes:
- Pre-size
Map[String, V]inFromJsonmap decoding using the JSON object’s length. - Add native benchmarks for decoding 10k and 100k-entry JSON objects into
Map[String, Int].
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| json/from_json.mbt | Pre-sizes the decoded Map[String, V] to reduce growth/rehashing during decode. |
| json/from_json_map_bench_test.mbt | Adds native benchmarks for Map::from_json decode at 10k/100k entries. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
bobzhang
force-pushed
the
perf/json-from-json-map-capacity
branch
from
August 26, 2026 07:44
f96cc0c to
8c53a88
Compare
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.
Summary
Map[String, V]from the input JSON object's known length.FromJsondecode.Benchmark
Apple M5, MoonBit
0.1.20260824, native release; lower is better.Command:
moon bench --release --target native json/from_json_map_bench_test.mbtValidation
moon test json --target all: 215 passed on each backendmoon checkmoon info; no public interface changes