Skip to content

Look up the key only once in the callback parser's key() - #5831

Merged
nlohmann merged 1 commit into
developfrom
claude/kind-goodall-cb86cf
Oct 15, 2026
Merged

nlohmann merged 1 commit into
developfrom
claude/kind-goodall-cb86cf

Conversation

@nlohmann

Copy link
Copy Markdown
Owner

Summary

Since #5466, json_sax_dom_callback_parser::key() searched the object for a duplicate key with find() and then looked the key up a second time with operator[] to insert the placeholder. That doubled the tree lookups per member and made json::parse(s, callback) on one very wide object slower than in 3.12.0. This replaces both lookups by a single emplace(); duplicate-key semantics (stash and restore) are unchanged.

Callback parse of {"k0":0,…,"k31999":31999} (Apple M1 Max, clang, -O3, median of 31, interleaved, machine under load):

3.12.0 develop this PR
8k members 1.9 ms 2.4 ms 1.7 ms
32k members 8.3 ms 10.5 ms 7.2–8.1 ms
128k members 35 ms 45 ms 31 ms

Comparing #5466 with its parent at 32k members: 7.3 ms vs 10.4 ms. Plain parsing is unchanged.

Tests: unit-class_parser, unit-diagnostic-positions, unit-regression2 pass.

API

No breaking changes.

🤖 Generated with Claude Code

@nlohmann nlohmann added this to the Release 3.13.0 milestone Oct 14, 2026
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
@nlohmann
nlohmann force-pushed the claude/kind-goodall-cb86cf branch from ddb5d36 to 908038c Compare October 15, 2026 06:24
@nlohmann
nlohmann added this pull request to stack #5841 October 15, 2026 06:24
@nlohmann nlohmann added the 🚀 ready to merge Ready to merge - just waiting for CI to complete. label Oct 15, 2026
@github-actions github-actions Bot added the M label Oct 15, 2026
@nlohmann
nlohmann merged commit a6e9785 into develop Oct 15, 2026
193 of 202 checks passed
@nlohmann
nlohmann deleted the claude/kind-goodall-cb86cf branch October 15, 2026 18:01
nlohmann added a commit that referenced this pull request Oct 16, 2026
Fixes every CI failure develop has had since the API performance stack (#5831-#5842) was merged: compiler warnings and errors (Clang, GCC 4.9/11, MSVC 2015/2017/2022), clang-tidy, cpplint, Cppcheck, IWYU, the examples check, the no-exceptions, diagnostic-positions, implicit-conversions and strict-NUL test configurations, and the MinGW link (now with LLD).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

M performance 🚀 ready to merge Ready to merge - just waiting for CI to complete.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants