~/talk

std::generator in C++23: When to use, and how to improve it

Talkat C++ on Sea 2025 · 2025-06-23..06-25· [c-and-cpp, concurrency]
links:none on file
slides:none on file

std::generator is type‑erased, allocates heap storage and shows measurable overhead vs inlinable code: a tiny two‑yield generator allocates 96 bytes on GCC and 64 bytes on Clang; microbenchmarks (Fibonacci-like loop, Google Benchmark with forced consumption) put its performance near virtual/indirect calls, not the inlinable case. Implementing a batched generator via a custom promise type and an awaitable suspend_if reduces per‑item cost, but compiler register spilling prevents full gains until manual assembly removes spills and cuts hot‑loop instructions by about 50%.

AI-written summary · about

  1. 0:00Introduction
  2. 1:49What is std::generator
  3. 15:33Performance considerations
  4. 26:28When to use std::generator
  5. 31:09Improving performance with batching
  6. 37:35Custom generator internals
  7. 49:15Why generators are slow
  8. 55:21Summary
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.