Skip to content

Commit faa543e

Browse files
authored
Update proposal.md
1 parent fdb316c commit faa543e

1 file changed

Lines changed: 68 additions & 12 deletions

File tree

cppcon2025/proposal.md

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,75 @@ Thankfully, C++ might soon be getting reflective metaprogramming ([PR2996](https
2222

2323
*You'll not be held to this—we understand that this is a snapshot in time.*
2424

25-
- JSON, performance and safety issues
26-
- C++20 elements: concepts, tag_invoke, constexpr
27-
- C++26 reflective metaprogramming: modest introduction
28-
- How we made use of it: serialization and deserialization
29-
- Quick perf analysis for our first working prototype (hint: it was not super fast!)
30-
- Optimizing the code: what made a difference!
31-
- Serialization benchmarks!
32-
- Deserialization benchmarks: Rust Serde and others.
33-
- Safety: Is it improved?
34-
- Downside: How challenging is reflective metaprogramming?
35-
- Downside: slower builds? (with numbers!)
36-
- Downside: difficult error messages (with examples!)
3725

26+
#### JSON, performance and safety issues
27+
- **Why JSON matters**: Brief recap of JSON’s ubiquity—web APIs, config files, data interchange—and its intuitive appeal (e.g., `{"age": 5, "name": "Daniel"}`).
28+
- **Performance bottlenecks**: Parsing complexity (string handling, nested structures), number parsing and serialization, serialization overhead, and the cost of manual mapping in C++.
29+
- **Safety pitfalls**: Type mismatches, unexpected input (e.g., broken Unicode), and lack of compile-time guarantees in traditional C++ JSON libraries.
30+
- **Motivation**: Contrast with languages like Rust (serde), Go or Python, where JSON handling is ergonomic—why C++ lags behind.
31+
32+
#### C++20 elements: concepts, tag_invoke, constexpr
33+
- **Concepts**: How they enable cleaner, more constrained interfaces.
34+
- **tag_invoke**: A customization point mechanism—how it simplifies generic serialization/deserialization hooks with less boilerplate.
35+
- **constexpr**: Leveraging compile-time computation for precomputed parsing or formatting logic.
36+
- **Setup for reflection**: These features lay the groundwork for metaprogramming but fall short of full automation.
37+
38+
#### C++26 reflective metaprogramming: modest introduction
39+
- **What it is**: Brief explanation of reflection (PR2996)—introspecting C++ types at compile time (e.g., fields of a struct, their names/types).
40+
- **Why it’s a game-changer**: No more manual mapping of JSON to structs; the compiler "knows" your data structures.
41+
- **Bloomberg LLVM fork**: Quick note on the experimental implementation—why we used it and its current state.
42+
- **Simple example**: Show a struct `Person { int age; std::string name; }` and how reflection exposes it for JSON.
43+
44+
#### How we made use of it: serialization and deserialization
45+
- **Core idea**: Reflection auto-generates code to map JSON to/from C++ structs (e.g., `Person` to `{"age": 5, "name": "Daniel"}`).
46+
- **Serialization**: Walking struct fields via reflection, emitting JSON strings at compile time where possible.
47+
- **Deserialization**: Parsing JSON tokens and populating structs, with type-safe error handling.
48+
- **Implementation details**: High-level overview—lexer, parser, and reflection-driven binder.
49+
50+
#### Quick perf analysis for our first working prototype (hint: it was not super fast!)
51+
- **Why it was slow**: Naive string handling and unoptimized reflection overhead.
52+
- **Lessons learned**: Early profiling showed us where to focus—set the stage for optimization.
53+
54+
#### Optimizing the code: what made a difference!
55+
- **Key wins**: Prepare keys at compile-time, SIMD for string ops.
56+
- **Anecdote**: Profiling experience is so-so.
57+
- **Result**: Leap to gigabytes per second.
58+
59+
#### Serialization benchmarks!
60+
- **Setup**: Describe test data and hardware.
61+
- **Numbers**: Compare our implementation to alternatives
62+
- **Visuals**: It is really fast! (But could be faster)
63+
64+
#### Deserialization benchmarks: Rust Serde and others
65+
- **Setup**: Describe test data (two complex JSON files) and hardware.
66+
- **Head-to-head**: Your lib vs. serde (Rust), nlohmann/json (C++), and others.
67+
- **Results**: We beat the alternatives (reflection + C++ control).
68+
- **System-dependent**: Processor type matters.
69+
70+
#### Safety: Is it improved?
71+
- **Compile-time checks**: Reflection catches type mismatches before runtime.
72+
- **Error handling**: Graceful fallback for malformed JSON, with clear diagnostics.
73+
- **Trade-offs**: More safety than handwritten code, but not foolproof (e.g., runtime edge cases).
74+
75+
#### Downside: How challenging is reflective metaprogramming?
76+
- **Learning curve**: Syntax and concepts are new—takes time to grok.
77+
- **Tooling**: Debugging reflection code is tricky.
78+
- **Audience hook**: "It’s like template metaprogramming’s wild cousin—powerful but untamed."
79+
80+
#### Downside: Slower builds? (with numbers!)
81+
- **Data**: Share compile-time costs.
82+
- **Why**: Reflection generates lots of code; LLVM fork isn’t optimized yet.
83+
- **Mitigation**: Precompiled headers or caching strategies you explored.
84+
85+
#### Downside: Difficult error messages (with examples!)
86+
- **Reality**: Reflection errors can be verbose and cryptic.
87+
- **Example**: Real errors one might encounter.
88+
- **Hope**: Compiler vendors will improve diagnostics as reflection matures
89+
90+
#### Conclusion
91+
- **How close?**: Should you try it today?
92+
- **How beneficial?**: How much help can you expect?
93+
- **How impactful?**: How much of a difference will it make?
3894

3995
## Preferred session length
4096

0 commit comments

Comments
 (0)