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

2

u/not_a_novel_account cmake dev Jul 11 '26 edited Jul 11 '26

Yes, if you change the facilities of the language you can do different things. That's outside the bounds of innovation within a C++ library.

Although frankly reducing below 20 cycles at risk of breaking the calling convention isn't a great spend of engineering time. The lower bound is something like 8 cycles but the indirect stall on the final jump is going to eat more than that every time anyway.

We're dealing in fractions of nanoseconds here for a fairly infrequent operation. It's totally transparent to most applications.

1

u/rentableshark Jul 11 '26

Yes, you are right but from a sort obsessive hygiene point of view, it has bothered me that it’s suboptimal and emits asm that is not necessarily the same as regular C++ context switches. I’m also not actually sure to what ABI C++ or clang/GCC adheres for non-inlined cpp->cpp function calls.

Philosophical nitpick: GCC plugins are just C++ code… a library if you will. I’m being pedantic and point taken,

1

u/not_a_novel_account cmake dev Jul 11 '26 edited Jul 11 '26

A compiler plugin is not a library consumed by the downstream user application, pedantically or otherwise. It's a toolchain component, like the compiler itself, or crt0.o. You can't ship a library which relies on a compiler plugin and have it build on my Debian base machine.

The C++ calling convention ABI is Itanium/SysV on Unix-like, and Win64 on Windows.