Skip to content

perf(json): presize maps during FromJson decode - #4139

Open
mizchi wants to merge 3 commits into
moonbitlang:mainfrom
mizchi:perf/json-from-json-map-capacity
Open

perf(json): presize maps during FromJson decode#4139
mizchi wants to merge 3 commits into
moonbitlang:mainfrom
mizchi:perf/json-from-json-map-capacity

Conversation

@mizchi

@mizchi mizchi commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Presize Map[String, V] from the input JSON object's known length.
  • Avoid repeated growth and rehashing during FromJson decode.
  • Add native release benchmarks for 10k and 100k entries.

Benchmark

Apple M5, MoonBit 0.1.20260824, native release; lower is better.

Entries Before After Improvement
10,000 464 µs 261 µs 43.7%
100,000 5.76 ms 3.54 ms 38.5%

Command: moon bench --release --target native json/from_json_map_bench_test.mbt

Validation

  • moon test json --target all: 215 passed on each backend
  • moon check
  • moon info; no public interface changes

Copilot AI lite review requested due to automatic review settings August 24, 2026 16:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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] in FromJson map 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.

Comment thread json/from_json.mbt Outdated
@bobzhang
bobzhang force-pushed the perf/json-from-json-map-capacity branch from f96cc0c to 8c53a88 Compare August 26, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants