Live data from Hacker News

How Rust optimizes async/await

tmandry.gitlab.io

1–10 of 130 posts

Re: How Rust optimizes async/await

#5
As a newcomer to Rust, wishing that this post was one of the first ones I've read about this topic. It took scouring through many many posts, some of them here on HN, to be able to grasp some of the same idea. (I may not be alone, judging from the very long discussion the other day: https://news.ycombinator.com/item?id=20719095)

Re: How Rust optimizes async/await

#7
post #6

We're getting generators as well? Awesome.

A future is a one-shot generator, give or take.

Good reading list at the bottom of https://areweasyncyet.rs, starting with this post that uses generators as an example: https://boats.gitlab.io/blog/post/2018-01-25-async-i-self-re...

Re: How Rust optimizes async/await

#8
post #6

We're getting generators as well? Awesome.

Not necessarily. They're an implementation detail of the compiler, and aren't fully baked yet to boot.

But there's plenty of reason to want generators, including the fact that they let you build streams. And the fact that async/await relies heavily on them has pushed the implementation much closer to being ready. I hope we get them at some point!

Re: How Rust optimizes async/await

#10

I don't quite follow. What exactly is the overhead that other languages have for futures that is eliminated here?

Most languages allocate every future (and sub-future, and sub-sub-future) separately on the heap. This leads to some overhead, allocating and deallocating space to store our task state.

In Rust, you can "inline" an entire chain of futures into a single heap allocation.

Post reply on HN