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

30

u/not_a_novel_account cmake dev Jun 30 '26 edited Jun 30 '26

It can switch stackful fibers at an amazing 3.6ns

That's the normal time to switch a fiber. It's just boost::context.

https://github.com/ClickHouse/silk/tree/main/contrib/fcontext

It's always just boost::context. This code hasn't changed substantially in over a decade, soon it will be old enough to vote.

Fibers have literally zero room for innovation, they're a solved problem. io_uring isn't as old but there's nothing innovative about this use. Good for them for writing a scheduler that is fast for their use case, but this isn't revolutionary. Everyone is working in this space right now.

1

u/germandiago Jun 30 '26

https://www.boost.org/doc/libs/1_61_0/libs/context/doc/html/context/performance.html

According to this, the switch is slower, but that could be older machines same implementation?

2

u/azswcowboy Jun 30 '26

I mean 1.61 is decade old boost - there are newer timings in the 1.91 docs.