Skip to content

Commit 6873e00

Browse files
committed
Prevent HALO in allocation benchmark with CAPY_NOINLINE
Clang's heap allocation elision was defeating the benchmark by placing coroutine frames on the stack. Adding noinline to each coroutine gives a fair comparison (Clang now shows ~190% speedup).
1 parent f1ad10d commit 6873e00

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

example/allocation/allocation.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
#include <iomanip>
2626
#include <iostream>
2727

28+
// Prevent HALO from eliding coroutine frame allocations
29+
#if defined(_MSC_VER)
30+
# define CAPY_NOINLINE __declspec(noinline)
31+
#elif defined(__GNUC__) || defined(__clang__)
32+
# define CAPY_NOINLINE __attribute__((noinline))
33+
#else
34+
# define CAPY_NOINLINE
35+
#endif
36+
2837
using namespace boost::capy;
2938

3039
std::atomic<std::size_t> counter{0};
@@ -34,31 +43,31 @@ std::atomic<std::size_t> counter{0};
3443
// business logic awaiting an HTTP client, awaiting
3544
// a TLS stream, awaiting a tcp_socket
3645

37-
task<> depth_4()
46+
CAPY_NOINLINE task<> depth_4()
3847
{
3948
counter.fetch_add(1, std::memory_order_relaxed);
4049
co_return;
4150
}
4251

43-
task<> depth_3()
52+
CAPY_NOINLINE task<> depth_3()
4453
{
4554
for(int i = 0; i < 3; ++i)
4655
co_await depth_4();
4756
}
4857

49-
task<> depth_2()
58+
CAPY_NOINLINE task<> depth_2()
5059
{
5160
for(int i = 0; i < 3; ++i)
5261
co_await depth_3();
5362
}
5463

55-
task<> depth_1()
64+
CAPY_NOINLINE task<> depth_1()
5665
{
5766
for(int i = 0; i < 5; ++i)
5867
co_await depth_2();
5968
}
6069

61-
task<> bench_loop(std::size_t n)
70+
CAPY_NOINLINE task<> bench_loop(std::size_t n)
6271
{
6372
for(std::size_t i = 0; i < n; ++i)
6473
co_await depth_1();

0 commit comments

Comments
 (0)