by klabb3 · 2y ago · 0 comments
The issue has more to do with thread lifecycle management, ie creating, maintaining a stack and destroying the thread. When you have very lightweight tasks, those add up and have no direct mitigations. That’s a big reason we moved runtimes into userspace.
I wish I could see the perf chart of these. If anyone finds them please link. It’s important to have objective facts to base these discussions in.
For thread creation, the author of the original post said "somewhere between 10 and 20 microseconds". This matches my own (very simple) benchmarks on my Ubuntu desktop, which was able to create and destroy just over 100k threads/second.
Depending on your use case, using a thread pool could mitigate this cost entirely.