Repository navigation
Replies: 1 comment
|
使用 测试的代码见 test_async_trait,在 std 环境下进行,分别使用两种方式实现了自定义 在读取缓冲区大小不同的情况下,分别测试了两百万次,在去除了冷启动、以及一些其他的开销后,最终使用 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment



Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
在 trait 中使用 async 关键字定义接口需要解决两个问题:
目前针对问题 1 的解决方案是
async_trait以及dynosaur这两个过程宏,但他们都会将返回值修改为Pin<Box<......>>,这样会带来堆的开销;针对问题 2,async_std 中的与 IO 相关的 trait 的定义提供了一种实现思路,并且能够支持动态分发;此外 StackFuture 也提供了一种方案;
最终讨论的结果详见 dyn-afit.
Using the async keyword in a trait to define an interface requires solving two problems:
Dynamic dispatch.
Reduce overhead.
The current solution to problem 1 is the two procedural macros
async_traitanddynosaur, but they will modify the return value toPin<Box<......>>, which will bring heap overhead;For problem 2, the definition of IO-related traits in async_std provides an implementation idea and can support dynamic dispatch; in addition, StackFuture also provides a solution;
For the final discussion results, see dyn-afit.
All reactions