Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition to poll_fn style backend traits #78

Closed
plaidfinch opened this issue Mar 25, 2021 · 2 comments
Closed

Transition to poll_fn style backend traits #78

plaidfinch opened this issue Mar 25, 2021 · 2 comments
Labels
enhancement New feature or request performance

Comments

@plaidfinch
Copy link
Contributor

Currently, the extra allocation and virtual call necessary for the boxed future returned by the backend traits leaves us about 50% slower on the microbenchmark against plain Tokio MPSC channels. Until just now, I thought this wasn't soluble without either proper async trait method support or GATs in Rust. However, this ignores the other remaining option: relinquish the design requirement that Transmit/Receive implementations be possible to write using async/await syntax.

If instead the traits are defined in terms of poll functions, similarly to how Sink and Stream are, we can define our own internal explicit futures that wrap an &mut Tx or &mut Rx and use these poll functions to provide the same interface. We could even provide extension traits TransmitExt/ReceiveExt to allow transmitters/receivers to be directly manipulated in async blocks. And all of this doesn't require any boxed future manipulations, which means it should compile away to essentially the same result as invoking the underlying transport directly.

@plaidfinch
Copy link
Contributor Author

plaidfinch commented Mar 25, 2021

This change is interrelated with #76, because the support for batching/buffering requires additional structure in the definition of Transmit. The two changes could be implemented in either order, but they will overwrite some of the same code, and therefore should not be implemented simultaneously.

@plaidfinch plaidfinch added enhancement New feature or request performance labels Mar 25, 2021
@plaidfinch
Copy link
Contributor Author

It further occurs to me that Transmit should be equivalent to Sink. But, Receive is not quite equivalent to Stream since (a) it has an error type and (b) its item type is a parameter, not an associated type. Is there an exact dual to Sink in a common library?

@sdleffler sdleffler added this to the 0.4 milestone Mar 27, 2021
@plaidfinch plaidfinch removed this from the 0.4 milestone Mar 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants