Skip to content

C++26 static reflection#2282

Merged
lemire merged 85 commits intomasterfrom
json_builder_init
Jul 14, 2025
Merged

C++26 static reflection#2282
lemire merged 85 commits intomasterfrom
json_builder_init

Conversation

@lemire
Copy link
Member

@lemire lemire commented Oct 29, 2024

Building our way up, this would add support for building JSON strings/documents using simdjson.

The end goal is to do:

kid k{12, "John", {"car", "ball"}};
simdjson::to_json(k);
// would generate {"age": 12, "name": "John", "toys": ["car", "ball"]}

We also add static-reflection support for deserialization so that you can do...

kid k = doc.get<kid>();

This works now, with a user-provided class.

See: Reflection-based JSON in C++ at Gigabytes per Second

With a version of LLVM supporting static reflection, the following might work:

CXX=clang++ cmake -B buildreflect -D SIMDJSON_STATIC_REFLECTION=ON  -DSIMDJSON_DEVELOPER_MODE=ON
cmake --build buildreflect --target static_reflection_builder_tests --verbose && ./buildreflect/tests/builder/static_reflection_builder_tests

We still need:

  • documentation (we need to create a new file build.md where we document the building)
  • benchmarks
  • more tests

Fixes: #1386

@lemire lemire added the enhancement New feature or request label Oct 29, 2024
@FranciscoThiesen
Copy link
Member

Merged with master since this branch is somewhat outdated now. Will resume working on it to fix the failing tests.

@lemire lemire marked this pull request as ready for review April 14, 2025 23:30
Daniel Lemire and others added 9 commits April 15, 2025 15:14
* Adding compilation benchmark for json parsing with and without reflection

* Moving it to the benchmark folder, also reducing a bit the number of iterations.

* Removing script from root folder.

* Reducing number of iterations

* Update benchmark/benchmark_reflection_usage_compilation.sh

Co-authored-by: Daniel Lemire <daniel@lemire.me>

* Update benchmark/benchmark_reflection_usage_compilation.sh

Co-authored-by: Daniel Lemire <daniel@lemire.me>

* Update benchmark/benchmark_reflection_usage_compilation.sh

Co-authored-by: Daniel Lemire <daniel@lemire.me>

* Making the script more customizable and also test whether the compiler being used supports reflection before actually running the benchmark

---------

Co-authored-by: Daniel Lemire <daniel@lemire.me>
…21/docs/papers/2025/p3491r2.html (#2389)

* Applying changes needed after latest reflection paper updates.

* Working, but no template for yet.

* Updating single-header to incldue the use of define_static_string.
@lemire lemire merged commit c806e95 into master Jul 14, 2025
136 of 142 checks passed
@lemire lemire deleted the json_builder_init branch July 14, 2025 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON builder

2 participants