Skip to content

perf(json): parse directly from string buffers#5108

Open
SaveTheRbtz wants to merge 1 commit into
Alexays:masterfrom
SaveTheRbtz:codex-json-parser-buffer
Open

perf(json): parse directly from string buffers#5108
SaveTheRbtz wants to merge 1 commit into
Alexays:masterfrom
SaveTheRbtz:codex-json-parser-buffer

Conversation

@SaveTheRbtz

@SaveTheRbtz SaveTheRbtz commented Jun 6, 2026

Copy link
Copy Markdown

Summary

  • Parse JsonParser input with JsonCpp CharReader directly from the existing string buffer.
  • Keep \x escape compatibility, but only allocate and run regex_replace when that escape is present.

Why this was needed

baseline.perf.data showed the JSON utility paying a large common-case regex tax before parsing:

  • std::regex search/replace: about 1.10B child cycles
  • std::regex::_M_dfs: 743M self cycles
  • Json parse path: 834M child cycles

Change

Parse from the existing string buffer with JsonCpp's CharReader. Preserve the \x compatibility repair, but first check whether the escape is present so the common path avoids allocating a modified string and running regex replacement.

Effect in comparison

The regex path disappears from visible hot symbols. Json parse work drops from 834M to 188M cycles, and the overall JsonCpp bucket drops from roughly 700M to 186M cycles.

Testing

  • ninja -C build
  • meson test -C build

@SaveTheRbtz

Copy link
Copy Markdown
Author

cc @zjeffer @xander1421 @Alexays, you look like the most relevant reviewers from git history:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant