TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #24916 20
Trying to implement fiber in C++20 coroutine

https://github.com/felixaszx/coro-fiber

I did some experiments with this. The result is very surprising. I tested this on my Ryzen 7700X (8c/16t) Windows 11.

This is barely optimized. But, its is able to outperform boost::fiber in single-thread context switching (\~20ns vs \~60ns, LLVM 21, std=c++20, the timer takes \~20ns). And even with the work stealing algorithm across all 16 threads trying to steal 1 fiber, it can still maitain at \~22ns of context switching.

I guess this is really uncommon since most of the time we expect our fiber to have some real workload rather than infinitely yielding to some other fibers. I am looking for some advices about how to improve the scheduler, right now it is just doing round robin locally or steal from other thread's queue if empty.

https://redd.it/1sbkbei
@r_cpp
GitHub GitHub - felixaszx/coro-fiber: A C++ coroutine library that provides a feel of fiber (user-land threading). A C++ coroutine library that provides a feel of fiber (user-land threading). - felixaszx/coro-fiber
More from @r_cpp
  1. Oct 6, 2026Tuning a Server for Benchmarking https://david.alvarezrosa.com/posts/tuning-a-server-for-b…
  2. Oct 6, 2026boost.org has been rebuilt: new profiles, badges, search, and library filtering The Boost…
  3. Oct 6, 2026When (Not) to Use alloca() https://voithos.io/articles/when-not-to-use-alloca/ https://red…
  4. Oct 6, 2026MSVC Build Tools Preview updates – September 2026 https://devblogs.microsoft.com/cppblog/m…
  5. Oct 6, 2026I built MrDocs, an open-source C++ reference doc generator on the Clang/LLVM AST. Looking…
  6. Oct 6, 2026WasmBolt — The LLVM Project in your browser https://anutosh21.github.io/WasmBolt/ https://…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →