Skip to content

Commit 67091e9

Browse files
committed
perf(async): optimize coroutine fast-path and remove redundant error helper
- introduce post_handle() fast path across scheduler/io_context - remove lambda-based coroutine resumption (direct handle posting) - optimize asio bridge (awaitable, tcp, udp, dns) - align thread_pool with coroutine fast-path (ctx_post_handle) - optimize timer and signal wakeups using handle-based resume - refactor when_all/when_any to use scheduler fast path - cleanup spawn_detached to avoid lambda overhead - remove duplicate cancelled_ec() from error.hpp (fix redefinition) - overall reduction of allocations and indirections in async hot path
1 parent 23e973c commit 67091e9

17 files changed

Lines changed: 955 additions & 527 deletions

include/vix/async/core/error.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <cstdint>
2020
#include <string>
2121
#include <system_error>
22+
#include <type_traits>
2223

2324
namespace vix::async::core
2425
{
@@ -114,7 +115,7 @@ namespace vix::async::core
114115
*
115116
* @return Category name ("async").
116117
*/
117-
const char *name() const noexcept override
118+
[[nodiscard]] const char *name() const noexcept override
118119
{
119120
return "async";
120121
}
@@ -125,7 +126,7 @@ namespace vix::async::core
125126
* @param c Integer value of the error code.
126127
* @return Human-readable error message.
127128
*/
128-
std::string message(int c) const override
129+
[[nodiscard]] std::string message(int c) const override
129130
{
130131
switch (static_cast<errc>(c))
131132
{
@@ -162,7 +163,7 @@ namespace vix::async::core
162163
*
163164
* @return Reference to the async error category.
164165
*/
165-
inline const std::error_category &category() noexcept
166+
[[nodiscard]] inline const std::error_category &category() noexcept
166167
{
167168
static error_category cat;
168169
return cat;
@@ -174,7 +175,7 @@ namespace vix::async::core
174175
* @param e Async error code.
175176
* @return Corresponding std::error_code.
176177
*/
177-
inline std::error_code make_error_code(errc e) noexcept
178+
[[nodiscard]] inline std::error_code make_error_code(errc e) noexcept
178179
{
179180
return {static_cast<int>(e), category()};
180181
}

include/vix/async/core/io_context.hpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ namespace vix::async::core
100100
}
101101

102102
/**
103-
* @brief Post a callable task to the scheduler.
103+
* @brief Post a generic callable task to the scheduler.
104+
*
105+
* This uses the scheduler generic path and is intended for ordinary callbacks.
104106
*
105107
* @tparam Fn Callable type.
106108
* @param fn Task to execute.
@@ -112,13 +114,23 @@ namespace vix::async::core
112114
}
113115

114116
/**
115-
* @brief Post a coroutine handle to the scheduler.
117+
* @brief Post a coroutine handle to the scheduler fast path.
118+
*
119+
* @param h Coroutine handle to resume.
120+
*/
121+
void post(std::coroutine_handle<> h) noexcept
122+
{
123+
sched_.post_handle(h);
124+
}
125+
126+
/**
127+
* @brief Explicit fast-path API for coroutine resumption.
116128
*
117129
* @param h Coroutine handle to resume.
118130
*/
119-
void post(std::coroutine_handle<> h)
131+
void post_handle(std::coroutine_handle<> h) noexcept
120132
{
121-
sched_.post(h);
133+
sched_.post_handle(h);
122134
}
123135

124136
/**
@@ -134,7 +146,7 @@ namespace vix::async::core
134146
/**
135147
* @brief Stop the scheduler.
136148
*
137-
* Causes run() to exit.
149+
* Causes run() to exit after draining pending work.
138150
*/
139151
void stop() noexcept
140152
{

0 commit comments

Comments
 (0)