Async/await optimizations could make language even more powerful

I realize rust has many benefits with borrow checker, but I hope it's clear that the true power rust brings is async/await

As you probably know, the way this is done in C++ is terrible (usually with hacky callbacks) - I have a whole blurb about this @ Evolution of asynchronous programming - Balanced Thoughts

Rust's future state machine, which allows allocation on the stack, is next-level - it can make async programming in embedded systems magical

Unfortunately, it seems there are a couple of small things in future state machine creation that results in binary bloat (especially important in embedded programming) - most of this is around "we made this async API just in case you need to wait on something; but often you don't & just have non-blocking code"; rust does poorly at optimizing the latter

The 2 big examples of this which I came across in my short time coding in rust (my hope is to make Matter, the smart home standard, shift to using rust):

This has been brought up previously, too:

2 Likes

Those are definitely optimizations we'd want to see happen, if someone is up for working on them.

2 Likes

This is a problem that we have been eyeing for a solution. #135527 could be a way to alleviate some of the pains. We have been thinking about cooperating with codegen backend(s) better so that better code could be emitted, when the backend understands coroutine dialect.

For that reason, we are proposing a project goal to enable a survey and experimentation.

2 Likes

I've touched bases with @dingxiangfei2009 (we're colleagues) & we're going to see if I can't help him make some magic & get these optimized, stay tuned!

5 Likes

There is also another project goal Async statemachine optimisation by diondokter · Pull Request #510 · rust-lang/rust-project-goals · GitHub just merged.

1 Like