Skip to content

Commit 1487c79

Browse files
Pushing latest changes
1 parent 41f3de9 commit 1487c79

File tree

1 file changed

+11
-71
lines changed

1 file changed

+11
-71
lines changed

cppcon2025/cppcon_2025_slides.md

Lines changed: 11 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,7 @@ std::string json_str = simdjson::to_json(player);
349349
Player player = simdjson::from<Player>(json_str);
350350
```
351351

352-
- **AT COMPILE TIME**
353-
- with no extra tooling
352+
- no extra tooling required
354353
- no annotation
355354

356355
---
@@ -397,48 +396,19 @@ Player deserialize_Player(const json& j) {
397396
# The Actual Reflection Magic
398397
399398
```cpp
400-
template <typename T>
401-
requires(std::is_class_v<T>) // For user-defined types
402-
error_code deserialize(auto& json_value, T& out) {
403-
simdjson::ondemand::object obj;
404-
auto er = json_value.get_object().get(obj);
405-
if(er) { return er; }
406-
// capture the attributes:
407-
constexpr auto members = std::define_static_array(std::meta::nonstatic_data_members_of(^^T,
408-
std::meta::access_context::unchecked()));
409-
410-
// This for loop happens at COMPILE TIME
411-
template for (constexpr auto member : members) {
412-
// These are compile-time constants
413-
constexpr std::string_view field_name = std::meta::identifier_of(member);
414-
constexpr auto member_type = std::meta::type_of(member);
415-
416-
// This generates code for each member
417-
auto err = obj[field_name].get(out.[:member:]);
418-
if (err && err != simdjson::NO_SUCH_FIELD) {
419-
return err;
420-
}
421-
};
422-
423-
return simdjson::SUCCESS;
399+
// Simplified snippet, members stores information about the class
400+
// obtained via std::define_static_array(std::meta::nonstatic_data_members_of(^^T, ...))...
401+
template for (constexpr auto member : members) {
402+
// These are compile-time constants
403+
constexpr std::string_view field_name = std::meta::identifier_of(member);
404+
constexpr auto member_type = std::meta::type_of(member);
405+
406+
// This generates code for each member
407+
obj[field_name].get(out.[:member:]);
424408
}
425409
```
426410

427-
---
428-
429-
430-
# The template for Statement
431-
432-
The `template for` statement is the key:
433-
434-
- It's like a **compile-time for-loop**
435-
- E.g., it generates code for each struct member
436-
- By the time your program runs, all reflection has been *expanded* into normal C++ code
437-
438-
This means:
439-
- **Zero runtime overhead**
440-
- **Full optimization opportunities**
441-
- **Type safety at compile time**
411+
See full implementation on [GitHub](https://github.com/simdjson/simdjson/blob/8aae14931d4f3cb0ef529ba5f7e2e34d7bcc8e19/include/simdjson/generic/ondemand/std_deserialize.h#L290)
442412

443413
---
444414

@@ -462,36 +432,6 @@ Player p = simdjson::from<Player>(json);
462432
// Runtime values flow through compile-time generated code
463433
```
464434
465-
---
466-
467-
# Zero Overhead: Why It's Fast
468-
469-
Since reflection happens at compile time, there's no runtime penalty:
470-
471-
1. **No runtime type inspection** - everything is known at compile time
472-
2. **No string comparisons for field names** - they become compile-time constants
473-
3. **Optimal code generation** - the compiler sees the full picture
474-
4. **Inline everything** - generated code can be fully optimized
475-
476-
The generated code is often **faster than hand-written code** because:
477-
- It's consistently optimized
478-
- No human errors or inefficiencies
479-
- Leverages simdjson's SIMD parsing throughout
480-
481-
---
482-
483-
# Performance: The Best Part
484-
485-
You might think "automatic = slow", but with simdjson + reflection:
486-
487-
- **Compile-time code generation**: No runtime overhead from reflection
488-
- **SIMD-accelerated parsing**: simdjson uses CPU vector instructions
489-
- **Zero allocation**: String views and in-place parsing
490-
- **Throughput**: ~2-4 GB/s on modern hardware
491-
492-
The generated code is often *faster* than hand-written code!
493-
494-
495435
---
496436
497437
# Real-World Benefits

0 commit comments

Comments
 (0)