CppCon 2018: G. Nishanov “Nano-coroutines to the Rescue! (Using Coroutines TS, of Course)”

Channel:CppCon · Length:1:04:25 · Published:2018-10-08 · Views:40352

Watch on YouTube

Summary

Gor Nishanov's CppCon 2018 talk on using tiny C++ coroutines to hide memory latency, interleaving useful work while prefetches bring cache lines in from main memory.

Why HN recommends it

Cited as a deep dive on coroutines for cache misses and on running huge numbers of coroutines without heap allocation.

also see this video that goes in depth how to have billions of coroutines with C++ — HN, 2019

C, C++, Rust, Go & systems languages · Software performance & optimization

Subtitles (excerpt)

- So, my name is Gor Nishanov. I am a developer in Visual C++ team, and one of the thing I work on is design and standardization of C++ coroutines. Most efficient, most scalable, most open coroutines of any programing language in existence. And, how many people attended any of the coroutine talks? We have about, okay, let's do it the other way around. So, we had probably, I think, every CppCon there is one or two coroutine talks. Who haven't been to any of them? Oops, okay. This will not be an introduction to coroutine. I put a few slides to give a context, but this still assumes that you are roughly aware how a C++ coroutines work, but don't worry, we'll have a few slides to get you up to speed. So coroutines is a very, very old abstraction. It is a bare function. It was invented 60 years ago by Melvin Conway, and Knuth gave it a more convenient definition as actually, he did the opposite. He said that the subroutine is a special case of a more general construction, which is a coroutine. And if we look at it, coroutines are just like functions but better, because they get two more operations. Just like normal functions which get call and return, coroutines get two more: suspend and resume.

On Hacker News

It's a big deal because, while it has some downsides, being stalkless means they can have next to no overhead, meaning it can be performant to use coroutines to write asynchronous code for even very fast operations. The example given [VIDEO] is that you can launch multiple coroutines to issue prefetch instructions and process the fetched data, so you can have clean code that issues multiple prefe… — BenFrantzDale, 2021-02
> In C++, technically every initialization of a sub-coroutine starts defaults to being a new heap allocation. I don't want to spread FUD: my understanding is that the vast majority of these are optimized out by the compiler. But one downside of this approach is that you could change your code and accidentally disable one of these optimizations. I don't think this is correct. C++ 20 allows a lot o… — je42, 2019-08
Gor Nishanov, one of the authors, talks about this in his CppCon2018 talk [VIDEO] (jump to ~12:33 to skip background). It amounts to using CPU prefetch instructions with C++ coroutines to simulate hyperthreading in software by scheduling instructions around cache misses (but is potentially better than hyperthreads because it's not limited to 2/core) — akubera, 2018-11

Related videos