You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As far as I understand, currently, async traits require heap allocation and dynamic dispatch on every invocation. The reason why this isn't supported seems to be linked in a blog post.
Eventually, I would like to find a way to have non-heap-allocated asynchronous trait methods. For now, the solution is ok, as our only goal is to be reasonably performant, not to be portable assembler.
"Micro-optimizations are the root of all evil"
—Some Guy Smarter Way Than Me
The text was updated successfully, but these errors were encountered:
async fn is just syntax sugar, and this could be done by transforming an async function like this:
asyncfndo_something(x:u32,y:u32) -> u32{let res = return_number().await;
x + y - res
}
Into this:
use std::future::Future;fndo_something(x:u32,y:u32) -> implFuture<Output = u32>{asyncmove{let res = return_number().await;
x + y - res
}}
However, impl Future<Output = u32> isn't a concrete type, so you can't name it, making this impossible in some cases. For most use cases though, this should work.
Whether this is worth it is up for discussion. As a point of reference, C++ 20 coroutines are always heap-allocated from what I can tell.
As far as I understand, currently, async traits require heap allocation and dynamic dispatch on every invocation. The reason why this isn't supported seems to be linked in a blog post.
Eventually, I would like to find a way to have non-heap-allocated asynchronous trait methods. For now, the solution is ok, as our only goal is to be reasonably performant, not to be portable assembler.
The text was updated successfully, but these errors were encountered: