Conversation
serializer always constructed a 512-byte indent_string, including compact dump() which never reads it. Grow the buffer on first pretty-print instead, using indent_char rather than a hardcoded space. Signed-off-by: elix3r <157088510+22elix3r@users.noreply.github.com>
|
FYI, there is an open PR that removes this buffer entirely. |
🔴 Amalgamation check failed! 🔴The source code has not been amalgamated and/or formatted correctly. 📎 A ready-to-apply patch is attached to the failed workflow run as the git apply amalgamation.patchThis does not require installing astyle yourself. |
|
@22elix3r CI is red: the build fails to compile with |
|
Thanks for this — and good catch on the indent-buffer regrowth using a hardcoded space fill instead of the configured This turns out to be superseded by already-in-progress maintainer work: #5285 (part of an active, currently-green stack) removes the — closed by Claude Code on behalf of @nlohmann |
Summary
Every
dump()constructed a 512-byteindent_stringeven for compact output (indent = -1), where the buffer is never read. That per-call heap allocation showed up as ~17% overhead on dump-many-small-values.Related Issue
Fixes #5413
Changes Made
indent_stringemptyensure_indent()usingindent_char(the previous doubling path filled with' ', which was wrong for a custom indent character)dump(2), anddump(1, '\\t')The
make_sharedoutput-adapter allocation from the issue is left for a follow-up; it is a larger adapter API change.Testing
Commands executed:
python3 tools/amalgamate/amalgamate.py -c tools/amalgamate/config_json.json -s .cmake -S . -B build -DJSON_BuildTests=ON -DCMAKE_BUILD_TYPE=Debugcmake --build build --target test-serialization_cpp11./tests/test-serialization_cpp11 --no-skip -tce='*downloaded*'./tests/test-serialization_cpp11 --no-skip -tce='*downloaded*' -tc='*5413*'Results:
Notes
Pretty-print still allocates a 512-byte (or larger) indent buffer the first time a nested indent is needed. Compact dump allocates none.
make amalgamate.