Re:Fewer mallocs in curl
by adrianN on Sunday April 23, 2017 @01:59PM
(#14179376)
Pulling a chunk off a freelist and maintaining that free list is most definitely not free.
[ Parent
| on HN ]
so what, to return from a freelist you alter the head pointer to point to the next item and return it
that's what, 2 or 3 instructions? even if you push that upto a few hundred it's still effectively free compared to anything else curl is going to do (e.g. writing to the disk)
A structure allocated in one chunk has cache locality and will be significantly faster to access than dereferencing multiple pointers.
The allocation itself is not the bottleneck, it's the poor choice of data structure.
Yup, malloc/free isn't usually algorithmically expensive but the cache misses tend to be the brutal part.
You'll spend 15 cycles doing work on 600 cycles of cache fetching. Plus you've just evicted some cache for your local scope.
Re:Fewer mallocs in curl
by nostrebored on Sunday April 23, 2017 @03:48PM
(#14180081)
you have to handle the case in which you have no remaining items as well, breaking up a chunk log(chunkToBreak/chunkSizeNeeded) times. And in the case that you have no viable chunk to use, you need to call back to the OS.