High-Level Effect Handlers in C++
summary
cpp-effects is a C++ library that implements deep, affine effect handlers on top of boost.context fibers, with handlers expressed as classes using multiple inheritance and optional named handlers to avoid RTTI. Examples include state, lightweight threads, actors and generators; resumptions capture delimited continuations (non-duplicable) and lifetimes use reference counting. Benchmarks show plain (non-resuming) commands are about 10x slower than direct globals but often competitive and sometimes faster than C++20 coroutines or libmprompt; exception interop is currently limited.
AI-written summary · about
chapters (15)
- 0:00Start
- 1:59Effects
- 3:58Effect handlers as composable user-defined operating systems
- 11:02flat handlers and plain commands
- 12:04lightweight threads with a kill command
- 14:35Example 6: async/await Futures
- 15:05generators
- 18:13Design summary
- 18:48Inheritance hierarchy for handlers
- 19:31Invoking a command
- 20:04Flat stack versus nested stack with pointers to stacklets (fibers)
- 20:19Implementation
- 20:54State using Clang natively (average time per iteration in ns)
- 22:24Generating a number (in ns)
- 22:55Recursive tree traversal (ns per node)
related talks
15mEffects as Capabilities: Effect Handlers and Lightweight Effect Polymorphism
12mCompiling Effect Handlers in Capability-Passing Style
16mContextual Effect Polymorphism Meets Bidirectional Effects (Extended Abstract)
15mEfficient Compilation of Algebraic Effect Handlers
22mLexical Effect Handler: Fast by Design, Correct by Proof
19mAssociated Effects: Flexible Abstractions for Effectful Programming
15mEffect Handlers, Evidently
15mZero-Overhead Lexical Effect Handlers
