|
|
|
|
|
by WalterBright
4069 days ago
|
|
> I've literally seen 20x or more speedups in multithreaded cases just by making sure I reuse every buffer rather than create new ones. Reuse rather than free and reallocate is a core practice whenever you feel the need for speed, regardless of the memory allocate strategy used. For some very fast D code: https://github.com/facebook/warp Minimizing the amount of heap memory allocated is a core strategy. |
|
Not that buffer reuse/avoiding heap allocations was unknown to me, it was just surprising to see this in an application that spent most of it's time waiting on the network.
I will say as a positive point that the equivalent D code to a C++ implementation was much cleaner due to build in array slicing among other things.
There are other areas where heap allocations are not so avoidable however (some hashmaps, some std's). My main point is that like at all languages, heap allocations are slow, but here they bear an unnecessarily large contention factor.
I really like D so I hope this is helpful feedback.