Repository navigation
[C++26] Reflection-based to_json/from_json: 672 lines replace NLOHMANN_DEFINE_TYPE_INTRUSIVE #5384
Replies: 2 comments
|
Thanks for the careful write-up. Measuring this on a real toolchain, with the method and your corrections included, is much more useful than guessing. The silent-omission problem with I read the branch and your
Tests should go under If this fits your plans, please open an issue proposing the minimal API (header name, annotation name, macro name) before writing more code. Then we can agree on the surface first. (This reply was drafted with Claude Code and reviewed by me.) |
I agree that this is good approach. I was thinking of this as I was watching a reflection and serialization talk at CppCon a couple weeks ago. I wonder if it would make sense to mimic some of the C# json library annotations. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
TL;DR
I replaced
NLOHMANN_DEFINE_TYPE_INTRUSIVEwith a P2996 static reflectioncodec on GCC 16 (
-std=c++26 -freflection) and measured the trade-offs.Headline results (single toolchain: g++-16 / nlohmann-json 3.12.0 / x86-64):
(same exe size at every N; text within 32 B).
(nested paths ~13–19% faster).
vs 238 (enable_if) / 376 (concepts) error cascades.
(naive flat-struct serializer). If the library ships the codec, user-side
break-even is 1 type.
The methodology and same-toolchain relationships are the durable findings.
Why this matters
NLOHMANN_DEFINE_TYPE_INTRUSIVEhas two known issues:dropped from serialization with zero diagnostics.
compiler already knows.
P2996 reflection promises to solve both. The question I set out to answer:
what does it actually cost?
Full report
The complete measurement log, protocol details, and corrections are in the repo:
docs/static-reflection/EVALUATION.md
This discussion post is a summary. The full report includes:
All reactions