r/cpp • u/germandiago • Jun 30 '26
Stackful fibers with 3.6ns context switch. Silk fibers.
https://clickhouse.com/blog/silkI 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
36
u/trailing_zero_count async enthusiast | TooManyCooks author Jun 30 '26 edited Jun 30 '26
Pretty cool, but a few criticisms:
The 3.6ns latency switch on fibers is a good headline if true, but the rest has a lot of marketing fluff.
31
u/not_a_novel_account cmake dev Jun 30 '26 edited Jun 30 '26
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.
7
u/tudorb Jun 30 '26
This is pretty cool, but the doc that you link to reads straight out of the mouth of Codex / Claude Code :)
3
u/User_Deprecated Jul 01 '26
one thing they skip over is how you batch sqe submissions around fiber yields. submit too eagerly and you're just doing syscalls, too lazily and your completions pile up.
1
u/Big_Target_1405 Jun 30 '26
Boost contexts ancient performance page puts a switch at 9ns (19 cycles) on a 10 year old CPU
https://www.boost.org/doc/libs/latest/libs/context/doc/html/context/performance.html
Surely there's a lower bound on what is possible here, given a full CPU state switch is required.
-3
u/_w62_ Jun 30 '26
Pardon my ignorances. I came from a networking background. After just a glance of the title, I am shocked that clickhouse is commencing a network gear division that offers 100G fiber switches.
After reading the text, fiber is a line of execution more lightweight than the thread.
Vielleicht reicht Englisch für die Computerindustrie nicht aus. Lassen Sie uns einige Fremdsprachen verwenden.