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
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
- How Python was Shaped by leaky Internals, Armin Ronacher, Flask framework · Видео с мероприятий {speach! · 49:55
- CppCon 2015: Andrei Alexandrescu “std::allocator...” · CppCon · 1:12:27
- Lexical Scanning in Go - Rob Pike · GoogleFOSSSydney · 51:17
- Preventing the Collapse of Civilization / Jonathan Blow (Thekla, Inc) · DevGAMM · 1:02:41
- "Performance Matters" by Emery Berger · Strange Loop Conference · 42:15
- The Thirty Million Line Problem · Molly Rocket · 1:48:55
- CppCon 2017: Matt Kulukundis “Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step” · CppCon · 59:33
- RustConf 2018 - Closing Keynote - Using Rust For Game Development by Catherine West · Rust Programming Language · 42:29
- Erlang Factory 2014 - That's 'Billion' with a 'B': Scaling to the Next Level at WhatsApp · Erlang Solutions · 49:15
- How Crash Bandicoot Hacked The Original Playstation | War Stories | Ars Technica · Ars Technica · 31:37
- "How NOT to Measure Latency" by Gil Tene · Strange Loop Conference · 42:59
- CppCon 2016: Jason Turner “Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17” · CppCon · 1:19:52
- Ideas about a new programming language for games. · Jonathan Blow · 1:55:24
- Refterm Lecture Part 1 - Philosophies of Optimization · Molly Rocket · 18:41
- CppCon 2014: Mike Acton "Data-Oriented Design and C++" · CppCon · 1:27:46
- How I program C · Eskil Steenberg · 2:11:32