4 ms·
I think the issue is not only the .NET spin loop implementation, but also that .NET in general is heavy on shared memory concurrency and required locking. Exam
by Matthias247 8y ago
I think the issue is not only the .NET spin loop implementation, but also that .NET in general is heavy on shared memory concurrency and required locking.
Examples: All the Concurrency primitives like Task<T> are thread-safe by default, and that has some associated cost. Other runtimes like javascript or other singlethreaded event loops don't have to pay for that cost, and might still be able to scale horizontally. Also the IO subsystem on .NET requires a lot of synchronization: Most IO callbacks (e.g. for sockets) will be made from an arbitrary Threadpool thread, which requires synchronization or marshaling to get back to another context. Again that will be cheaper on a runtime where the whole event sources and consumers are using the same thread.
I certainly can't quantify it in numbers, but I guess .NET has some of the highest requirements regarding synchronization performance. At least the standard libs, there are obviously some efforts underway to improve that situation.