-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Drop async_trait #1556
base: master
Are you sure you want to change the base?
Drop async_trait #1556
Conversation
@matze Nice! I think we could potentially offer this as an opt-in during codegen? I don't think there is anything stopping us from support both since its mostly codegen and user callsite code that is affected. What do you think? |
|
@LucioFranco I tested but the initial caveat still holds, all crates using pre-generated services require either |
A similar PR is approved for axum, how do you think just breaking as well? |
I am not following what you mean by this?
I think we should if we can get it so it works for both and users can choose. |
I mean I don't see how this could ever work for both. |
e17975e
to
04e79a4
Compare
c3eaecc
to
6fcc971
Compare
Firstly let me say that I don't want to come across as prescriptive. Like many others, I'd like to see However, In my view, I'd like to see tonic stamp out a new major version (the fabled 1.0, perhaps?) that drops This is a lot of work for the tonic maintainers. This is potentially a lot of work for tonic users. But, I think it balances the trade off without unduly burdening anyone.
|
Ultimately I think the constraints here are:
At the same time, I do wonder what the motivation is to get rid of async-trait? Have you measured a large effect on performance in your workloads? Or a large effect on compile-time due to the extra macros/dependency? |
If axum is any indication, latency and throughput improved measurably but not with "large effect". For me personally this is of lower priority, not having to deal with generated, intransparent code is more important especially if there are alternatives out-of-the-box. |
Obviously, we would like to drop it eventually, but the current state of async traits is not in its final state and it has a few issues that are left to be resolved before I would even consider it something to widely support in a library like this. Unless someone can put forth some valid data showing that there is a legit perf improvement to dropping async-trait then I don't think its worth investing on this right now versus other streams of work for tonic. |
Motivation
This change was born mostly out of curiosity rather than a serious attempt to get it in any time soon. The main motivation of course is to get rid of the
async_trait
macro and boxed futures in favor of recently stabilizedasync fn
in traits.Solution
Remove usage of the
async_trait
macro and adjust the server codegen parts to return desugaredimpl Future<…> + Send
because of the Send bound problem.Caveats
This requires a nightly compiler but with that passes all tests as well as some manual tests I performed.
The larger question to answer though is how this would be merged into tonic eventually.
tonic-health
andtonic-reflection
rely on generated code which prohibits a gradual, feature-based integration. Moreover, this would require quite a large bump of MSRV to 1.75.