C++ Coroutines at Scale - Implementation Choices at Google
summary
Google runs C++ coroutines in production to process billions of RPCs/sec and the K3 library trades ergonomics for safety: a marker return type Co forces immediate await vs an opt‑in future that deep‑copies arguments to avoid dangling temporaries. Cancellation is mandatory — cancelled coroutines stop at next suspension and only run destructors — and the runtime never lets one coroutine resume another on the same thread, using a thread‑local queue to keep stack use bounded on 64KB stacks.
AI-written summary · about
chapters (18)
- 0:00Introduction and overview
- 1:27Scale at Google and coroutines
- 4:13Use case for coroutines
- 5:36Basics of the coroutine library
- 8:23Lifetime rules for coroutine parameters
- 13:39Challenges with reference parameters
- 17:50Design choice for parameter lifetimes
- 21:01Future class for delayed awaiting
- 25:31Thread stack usage at Google
- 28:40Bounding stack usage with coroutines
- 32:28Resuming coroutines safely
- 37:29Event class and executor design
- 40:51Importance of cancellation support
- 42:40Cancellation design in the library
- 45:10Concurrency APIs and structured concurrency
- 52:31Unstructured concurrency and stack overflows
- 1:01:12Recap of design goals and trade-offs
- 1:04:40Q&A session
related talks
58m“Introduction to C++ Coroutines"
52mCoroutines: C++ vs Rust
01h 06mC++ Coroutines from scratch
01h 16mC++ Feature Coroutines, Beginner Friendly
48m“Coroutines: what can't they do?”
01h 01mUnderstanding C++ Coroutines by Example, Part 1
48mStructured Concurrency: Writing Safer Concurrent Code with Coroutines...
58m“C++ Coroutines - a negative overhead abstraction"
