Skip to content

Commit 8752880

Browse files
committed
RObjectBuilder optimized.
1 parent 652ebee commit 8752880

File tree

20 files changed

+258
-290
lines changed

20 files changed

+258
-290
lines changed

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

RTLBenchmarkApp/src/BenchMark.cpp

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
namespace {
1313

14-
static const char* LONG_STR = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do"
15-
"do aeiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis"
16-
"nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure"
17-
"dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Except"
18-
"eur ssint occaecat cupidatat nnon proident, sunt in culpa qui officia deserunt mollit anim id";
14+
static const char* LONG_STR = "Lorem ipsum";// dolor sit amet, consectetur adipiscing elit, sed do";
15+
//"do aeiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis"
16+
//"nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure"
17+
//"dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Except"
18+
//"eur ssint occaecat cupidatat nnon proident, sunt in culpa qui officia deserunt mollit anim id";
1919
}
2020

2121
// Pre-created string to isolate call overhead
22-
static const std::string g_longStr(LONG_STR);
22+
static argStr_t g_longStr(LONG_STR);
2323

2424
namespace rtl_bench
2525
{
@@ -33,23 +33,9 @@ namespace rtl_bench
3333
}
3434

3535

36-
void BenchMark::autoLambdaCall_noReturn(benchmark::State& state)
37-
{
38-
static auto sendMsg = [](const str_type& pMsg) {
39-
sendMessage(pMsg);
40-
};
41-
42-
for (auto _ : state)
43-
{
44-
sendMsg(g_longStr);
45-
benchmark::DoNotOptimize(g_msg);
46-
}
47-
}
48-
49-
5036
void BenchMark::stdFunctionCall_noReturn(benchmark::State& state)
5137
{
52-
static std::function sendMsg = [](const str_type& pMsg) {
38+
static std::function sendMsg = [](argStr_t& pMsg) {
5339
sendMessage(pMsg);
5440
};
5541

@@ -60,6 +46,7 @@ namespace rtl_bench
6046
}
6147
}
6248

49+
6350
void BenchMark::directCall_withReturn(benchmark::State& state)
6451
{
6552
static auto _ = []() {
@@ -70,33 +57,22 @@ namespace rtl_bench
7057

7158
for (auto _ : state)
7259
{
73-
benchmark::DoNotOptimize(getMessage(g_longStr));
74-
}
75-
}
76-
77-
78-
void BenchMark::autoLambdaCall_withReturn(benchmark::State& state)
79-
{
80-
auto getMsg = [](const str_type& pMsg) {
81-
return getMessage(pMsg);
82-
};
83-
84-
for (auto _ : state)
85-
{
86-
benchmark::DoNotOptimize(getMsg(g_longStr));
60+
volatile std::string forced = std::move(getMessage(g_longStr)); // ensures real move
61+
benchmark::DoNotOptimize(forced);
8762
}
8863
}
8964

9065

9166
void BenchMark::stdFunctionCall_withReturn(benchmark::State& state)
9267
{
93-
static std::function getMsg = [](const str_type& pMsg) {
68+
static std::function getMsg = [](argStr_t& pMsg) {
9469
return getMessage(pMsg);
9570
};
9671

9772
for (auto _ : state)
9873
{
99-
benchmark::DoNotOptimize(getMsg(g_longStr));
74+
volatile std::string forced = std::move(getMsg(g_longStr)); // ensures real move
75+
benchmark::DoNotOptimize(forced);
10076
}
10177
}
10278
}
@@ -109,7 +85,7 @@ namespace rtl_bench
10985
static rtl::Function sendMsg = cxx_mirror().getFunction("sendMessage").value();
11086

11187
static auto _ = []() {
112-
if (sendMsg.bind<str_type>().call(g_longStr).err == rtl::error::None) {
88+
if (sendMsg.bind().call(g_longStr).err == rtl::error::None) {
11389
std::cout << "[rtl:0] call success.\n";
11490
}
11591
else {
@@ -120,7 +96,7 @@ namespace rtl_bench
12096

12197
for (auto _ : state)
12298
{
123-
benchmark::DoNotOptimize(sendMsg.bind<str_type>().call(g_longStr));
99+
benchmark::DoNotOptimize(sendMsg.bind().call(g_longStr));
124100
}
125101
}
126102

@@ -131,7 +107,7 @@ namespace rtl_bench
131107
static rtl::Method sendMsg = rNode.getMethod("sendMessage").value();
132108
static rtl::RObject robj = rNode.create<rtl::alloc::Stack>().rObject;
133109
static auto _ = []() {
134-
if (sendMsg.bind<str_type>(robj).call(g_longStr).err == rtl::error::None) {
110+
if (sendMsg.bind(robj).call(g_longStr).err == rtl::error::None) {
135111
std::cout << "[rtl:1] call success.\n";
136112
}
137113
else {
@@ -142,7 +118,7 @@ namespace rtl_bench
142118

143119
for (auto _ : state)
144120
{
145-
benchmark::DoNotOptimize(sendMsg.bind<str_type>(robj).call(g_longStr));
121+
benchmark::DoNotOptimize(sendMsg.bind(robj).call(g_longStr));
146122
}
147123
}
148124

@@ -151,7 +127,7 @@ namespace rtl_bench
151127
{
152128
static rtl::Function getMsg = cxx_mirror().getFunction("getMessage").value();
153129
static auto _ = []() {
154-
if (getMsg.bind<str_type>().call(g_longStr).err == rtl::error::None) {
130+
if (getMsg.bind().call(g_longStr).err == rtl::error::None) {
155131
std::cout << "[rtl:2] call success.\n";
156132
}
157133
else {
@@ -162,7 +138,7 @@ namespace rtl_bench
162138

163139
for (auto _ : state)
164140
{
165-
benchmark::DoNotOptimize(getMsg.bind<str_type>().call(g_longStr));
141+
benchmark::DoNotOptimize(getMsg.bind().call(g_longStr));
166142
}
167143
}
168144

@@ -173,7 +149,7 @@ namespace rtl_bench
173149
static rtl::Method getMsg = rNode.getMethod("getMessage").value();
174150
static rtl::RObject robj = rNode.create<rtl::alloc::Heap>().rObject;
175151
static auto _ = []() {
176-
if (getMsg.bind<str_type>(robj).call(g_longStr).err == rtl::error::None) {
152+
if (getMsg.bind(robj).call(g_longStr).err == rtl::error::None) {
177153
std::cout << "[rtl:3] call success.\n";
178154
}
179155
else {
@@ -184,7 +160,7 @@ namespace rtl_bench
184160

185161
for (auto _ : state)
186162
{
187-
benchmark::DoNotOptimize(getMsg.bind<str_type>(robj).call(g_longStr));
163+
benchmark::DoNotOptimize(getMsg.bind(robj).call(g_longStr));
188164
}
189165
}
190166
}

RTLBenchmarkApp/src/BenchMark.h

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,30 @@
1212
# define NOINLINE
1313
#endif
1414

15-
using str_type = /*std::string; //*/ std::string_view;
15+
using argStr_t = std::string_view;
16+
using retStr_t = std::string;
1617

1718
namespace rtl_bench
1819
{
1920
static std::optional<std::string> g_msg;
2021

21-
NOINLINE static void sendMessage(str_type pMsg) {
22-
std::string result = std::string(pMsg) + std::string(pMsg);
23-
result = result + result;
24-
result = result + result;
22+
NOINLINE static void sendMessage(argStr_t pMsg) {
2523
g_msg = pMsg;
2624
}
2725

28-
NOINLINE static str_type getMessage(str_type pMsg) {
29-
std::string result = std::string(pMsg) + std::string(pMsg);
30-
result = result + result;
31-
result = result + result;
32-
g_msg = pMsg;
33-
return str_type(g_msg->c_str());
26+
NOINLINE static retStr_t getMessage(argStr_t pMsg) {
27+
return retStr_t(pMsg);
3428
}
3529

3630
struct Node
3731
{
38-
NOINLINE void sendMessage(str_type pMsg) {
39-
std::string result = std::string(pMsg) + std::string(pMsg);
40-
result = result + result;
41-
result = result + result;
42-
g_msg = pMsg;
32+
NOINLINE void sendMessage(argStr_t pMsg) {
4333
g_msg = pMsg;
4434
}
4535

46-
NOINLINE str_type getMessage(str_type pMsg)
36+
NOINLINE retStr_t getMessage(argStr_t pMsg)
4737
{
48-
std::string result = std::string(pMsg) + std::string(pMsg);
49-
result = result + result;
50-
result = result + result;
51-
g_msg = pMsg;
52-
return str_type(g_msg->c_str());
38+
return retStr_t(pMsg);
5339
}
5440
};
5541

@@ -60,7 +46,7 @@ namespace rtl_bench
6046

6147
rtl::type().record<Node>("Node").build(),
6248

63-
rtl::type().function<str_type>("sendMessage").build(sendMessage),
49+
rtl::type().function("sendMessage").build(sendMessage),
6450

6551
rtl::type().member<Node>().method("sendMessage").build(&Node::sendMessage),
6652

@@ -76,8 +62,6 @@ namespace rtl_bench
7662
{
7763
static void directCall_noReturn(benchmark::State& state);
7864

79-
static void autoLambdaCall_noReturn(benchmark::State& state);
80-
8165
static void stdFunctionCall_noReturn(benchmark::State& state);
8266

8367
static void reflectedCall_noReturn(benchmark::State& state);
@@ -86,8 +70,6 @@ namespace rtl_bench
8670

8771
static void directCall_withReturn(benchmark::State& state);
8872

89-
static void autoLambdaCall_withReturn(benchmark::State& state);
90-
9173
static void stdFunctionCall_withReturn(benchmark::State& state);
9274

9375
static void reflectedCall_withReturn(benchmark::State& state);

RTLBenchmarkApp/src/main.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77

88
BENCHMARK(rtl_bench::BenchMark::directCall_noReturn);
9-
BENCHMARK(rtl_bench::BenchMark::autoLambdaCall_noReturn);
109
BENCHMARK(rtl_bench::BenchMark::stdFunctionCall_noReturn);
1110
BENCHMARK(rtl_bench::BenchMark::reflectedCall_noReturn);
1211
BENCHMARK(rtl_bench::BenchMark::reflectedMethodCall_noReturn);
1312

1413
BENCHMARK(rtl_bench::BenchMark::directCall_withReturn);
15-
BENCHMARK(rtl_bench::BenchMark::autoLambdaCall_withReturn);
1614
BENCHMARK(rtl_bench::BenchMark::stdFunctionCall_withReturn);
1715
BENCHMARK(rtl_bench::BenchMark::reflectedCall_withReturn);
1816
BENCHMARK(rtl_bench::BenchMark::reflectedMethodCall_withReturn);

RTLTestRunApp/src/CxxMirrorTests/CxxMirrorObjectTest.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ namespace
1111
const rtl::CxxMirror cxx_mirror()
1212
{
1313
return rtl::CxxMirror({
14-
15-
// Registering void as a record type (valid type but has no members/constructors).
16-
// Demonstrates that RTL can explicitly represent even fundamental non-instantiable types.
17-
rtl::type().record<void>("void").build(),
18-
19-
// Example of compile-time safety: constructors for void are invalid, RTL enforces this.
20-
// rtl::type().member<void>().constructor<int>().build(), // <- will not compile
2114

2215
// Register char as a record type (fundamental but instantiable).
2316
rtl::type().record<char>("char").build(),

RTLTestRunApp/src/CxxMirrorTests/CxxMirrorThreadingTest.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ namespace rtl_tests
9999

100100
rtl::type().function("strlen").build(std::strlen),
101101

102-
rtl::type().record<void>("void").build(),
103-
104102
rtl::type().record<char>("char").build(),
105103

106104
rtl::type().record<std::vector<int>>("vector_int").build(),

RTLTestRunApp/src/FunctionalityTests/MoveConstructorTests.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ namespace rtl_tests
4949

5050
// 'calander0' must be empty now.
5151
ASSERT_TRUE(calender0.isEmpty());
52-
EXPECT_NE(calender0.getTypeId(), calender1.getTypeId());
5352

5453
// After move, these instance count must remain same.
5554
EXPECT_TRUE(calender::get_instance_count() == 1);
@@ -114,7 +113,6 @@ namespace rtl_tests
114113

115114
// 'calander0' must be empty now.
116115
ASSERT_TRUE(calender0.isEmpty());
117-
EXPECT_NE(calender0.getTypeId(), calender1.getTypeId());
118116

119117
// After move, these instance count must remain same.
120118
EXPECT_TRUE(calender::get_instance_count() == 1);
@@ -184,7 +182,6 @@ namespace rtl_tests
184182

185183
// 'event0' must be empty now.
186184
ASSERT_TRUE(event0.isEmpty());
187-
EXPECT_NE(event0.getTypeId(), event1.getTypeId());
188185
{
189186
// Event::reset() is a non-const method. can't be called on const-object.
190187
optional<Method> eventReset = classEvent->getMethod(event::str_reset);
@@ -257,7 +254,6 @@ namespace rtl_tests
257254

258255
// 'calander0' must be empty now.
259256
ASSERT_TRUE(calender0.isEmpty());
260-
EXPECT_NE(calender0.getTypeId(), calender1.getTypeId());
261257

262258
// After move, these instance count must remain same.
263259
EXPECT_TRUE(calender::get_instance_count() == 1);

0 commit comments

Comments
 (0)