3 ms·
In a many cases, attempting to spread your problem across as many threads/cores/computers as you can will cause more harm than good. Sometimes we do things on
by bob1029 5y ago
In a many cases, attempting to spread your problem across as many threads/cores/computers as you can will cause more harm than good.
Sometimes we do things on only one thread because its faster than doing it on all the threads.
- spacemanmatt 5y agoIf your problem is small enough fore one thread it's not interesting here
- bob1029 5y agoHere is a problem that is small enough for one thread: https://lmax-exchange.github.io/disruptor/disruptor.html https://lmax-exchange.github.io/disruptor/disruptor.html A financial exchange does order matching at rates of millions of transactions per second on a single thread because its literally the fastest way to do things. Would you consider operating the most important part of any financial exchange on a single thread "not interesting"?
- spacemanmatt 5y agoWould you consider a concurrent system executed by a single thread in a financial exchange to exemplify "indie devs avoid multithreading?"
- bob1029 5y agoThe point I am ultimately trying to make is that, in many cases, the reason to avoid multi-threading is because it's not actually the fastest way to do something. It's that simple. The implicit concern (if you could not infer from the content of my link above) being that the developer community is completely blind to the performance capabilities of a single computer/core/thread in 2022 and are inclined to automatically skip over these simple solutions in favor of a multi-threaded solution.
- spacemanmatt 5y agoI feel like that is a point that doesn't need making because it's sorta elementary that task switching is expensive and avoidable in some cases. Especially when the explicit context is indie development, not squeezing some performance out of the threading model at large scale.
- PaulHoule 5y agoThe essential practice (frequently ignored) is that you have to break the task into subtasks that take more time than the time to split between tasks. You usually can get away with a wide range (orders of magnitude) of subtask sizes that get a good speedup so you don't have to tune it exactly. Whenever I try to get a parallel speedup I build some kind of batching before I do the actual subtask execution because almost always the smallest level of granularity is too small so instead of getting a 4x speedup on four cores you get a 20x slowdown. Whenever I do this in a "hackathon" environment with others I end up feeling like a Cassandra because the other people think that batching is optional or an optimization but unless the natural granularity of your task is huge it's essential if your goal is getting speedup.