r/cpp • • Jun 30 '26

Stackful fibers with 3.6ns context switch. Silk fibers.

https://clickhouse.com/blog/silk

I just read an article about Silk, the new stackful fibers engine from Clickhouse. It can switch stackful fibers at an amazing 3.6ns and does not allocate on steady state.

Maybe asio could reuse some of the knowledge for the linux/io_uring backend (not sure it applies to the specific case since Boost.asio focuses nowadays on stackless, though it has a fibers and a stackful coros backend also).

51 Upvotes

25 comments sorted by

View all comments

Show parent comment

15

u/not_a_novel_account cmake dev Jun 30 '26

That's why I linked the code, it's literally boost::context, as in, a vendored copy of the code which says "this is boost::context".

You could achieve identical performance for switching using boost::context since Kowalke wrote the code 14 years ago.

That's the first thing I checked because there haven't been any new ISA changes which would make this faster, so I was curious what innovation they could have found. I figured maybe they were on some architecture I wasn't familiar with, or were violating the calling convention in order to shave off register spills. Nope, boost::context.

The rest is a lot of work, good allocators are hard, io_uring from scratch is not a cakewalk, so on and so forth. But there's nothing here you won't find equivalent versions of in Seastar or implemented at any high-performance Linux shop east of the Mississippi.

1

u/Fabulous-Meaning-966 Jul 07 '26

Maybe the least trivial part is writing your own sync primitives.

-3

u/germandiago Jun 30 '26

Well, Seastar went stackless actually. The stackful seastar implementation is heavier, for what I understood after a few prompt questions to AI (which could be wrong).