Skip to content

Commit 4688d7b

Browse files
authored
optimization-centric refactor
- removed unnecessary try/catch blocks (RTL is now exception-free internally) - added forced inlining on critical paths - introduced scaling-workload benchmark setup - added initial benchmark report
2 parents 0220696 + 4e15904 commit 4688d7b

26 files changed

+655
-420
lines changed

BenchMarkReport_0.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Reflection Template Library (RTL) — Benchmark Report
2+
3+
This document presents benchmark results for the **Reflection Template Library (RTL)**.
4+
The goal was to measure the runtime overhead of reflective function calls compared to direct calls and `std::function`, under increasing workloads.
5+
6+
---
7+
8+
## Benchmark Setup
9+
10+
We tested:
11+
12+
- **Direct calls** (baseline).
13+
- **`std::function` calls** and method calls.
14+
- **RTL reflective calls** (free functions and member methods, with and without return values).
15+
16+
Each benchmark was repeated across workloads of increasing complexity, with times measured in nanoseconds.
17+
18+
---
19+
20+
## Results Summary
21+
22+
| Workload | Direct Call (ns) | Reflected Call Overhead (ns) | Reflected Method Overhead (ns) | Notes (With Return) |
23+
|-----------------|------------------|------------------------------|--------------------------------|---------------------|
24+
| baseline_40ns | 39.0 / 44.7 | +2.5 | +6.6 | +10.6 / +14.3 |
25+
| workload_80ns | 82.4 / 82.5 | ~0 | ~0 | +12.5 / +15.6 |
26+
| workload_100ns | 94.2 / 100.0 | +1.4 | +8.8 | +12.0 / +16.0 |
27+
| workload_150ns* | 139.0 / 158.0 | +2–3 | +14–17 | +12–13 / +17–19 |
28+
29+
\*Three independent runs were recorded at ~150 ns workload; numbers are consistent.
30+
31+
---
32+
33+
## Insights
34+
35+
- **Constant Overhead**
36+
Reflection overhead remains almost constant across workloads:
37+
- No-return functions: **+2–6 ns**.
38+
- Return-value functions: **+10–20 ns**.
39+
40+
- **Percentage Overhead Shrinks**
41+
- At the 40 ns baseline, overhead was ~25%.
42+
- By ~150 ns workloads, overhead dropped below 10%.
43+
44+
- **No Scaling Penalty**
45+
The overhead does not grow with function complexity.
46+
This indicates that RTL adds only a fixed, predictable cost per call, with no hidden allocations.
47+
48+
- **Performance-Culture Friendly**
49+
This aligns with C++’s ethos: *you only pay a small, predictable cost when you use reflection*.
50+
51+
---
52+
53+
## Conclusion
54+
55+
The Reflection Template Library (RTL) demonstrates:
56+
57+
- **Runtime reflection with constant, minimal overhead**.
58+
- **Predictable cost model**: ~10–20 ns for reflective calls with returns.

CxxRTLTypeRegistration/inc/TestMirrorProvider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace test_mirror
2222
static std::size_t calender;
2323

2424
static std::size_t char_t;
25-
static std::size_t void_t;
25+
static std::size_t int_t;
2626
static std::size_t std_string;
2727
static std::size_t std_string_view;
2828

CxxRTLTypeRegistration/src/TestMirrorProvider.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ namespace test_mirror
3737
--------------------------------- */
3838

3939
// Registering void, valid but not useful at all.
40-
rtl::type().record<void>("void").build(),
40+
rtl::type().record<int>("int").build(),
4141

4242
// Registering type 'void' again, ignored & emits-
4343
// [WARNING] Multiple registrations of the same type detected.
44-
rtl::type().record<void>("void").build(),
44+
rtl::type().record<int>("int").build(),
4545

4646
// Registering type 'void' again, but with different name. ignored & emits-
4747
// [WARNING] Multiple registrations of the same type detected.
48-
rtl::type().record<void>("ccvoid").build(),
48+
rtl::type().record<int>("ccint").build(),
4949

5050
// Registering pod, reflecting- constructor, copy-constructor & destructor.
5151
rtl::type().record<char>("char").build(),
@@ -266,7 +266,7 @@ namespace test_mirror
266266
std::size_t reflected_id::event = rtl::detail::TypeId<nsdate::Event>::get();
267267
std::size_t reflected_id::calender = rtl::detail::TypeId<nsdate::Calender>::get();
268268

269-
std::size_t reflected_id::void_t = rtl::detail::TypeId<void>::get();
269+
std::size_t reflected_id::int_t = rtl::detail::TypeId<int>::get();
270270
std::size_t reflected_id::char_t = rtl::detail::TypeId<char>::get();
271271
std::size_t reflected_id::std_string = rtl::detail::TypeId<std::string>::get();
272272
std::size_t reflected_id::std_string_view = rtl::detail::TypeId<std::string_view>::get();
@@ -277,7 +277,7 @@ namespace test_mirror
277277
static std::unordered_map<std::string, std::size_t> nameIdMap(
278278
{
279279
{ "char", char_t },
280-
{ "void", void_t },
280+
{ "int", int_t },
281281
{ "string", std_string },
282282
{ "string_view", std_string_view },
283283

0 commit comments

Comments
 (0)