by misir on 11/26/22, 9:10 PM with 12 comments
by joosters on 11/29/22, 6:37 AM
by ww520 on 11/29/22, 4:48 PM
by fatih-erikli on 11/29/22, 7:37 AM
by shoo on 11/29/22, 10:31 AM
one downside of linked lists is that each node in the list can reside in an arbitrary part of memory. in the worst case each traversal of a link is a cache miss, so you sit around for 100 or 200 cycles waiting for a main memory read. similarly if all the values in the list that are used to implement comparisons are also stored by reference and scattered throughout memory.
with heaps, another interesting thing to try is switching from a binary heap to e.g. a 4-ary heap (i.e. 4 children per parent). i've been fiddling with heaps recently for a priority queue & see a decent speedup switching to a 4-ary heap -- provided the "heapify down" logic that runs whenever you pop an element is structured to let the cpu do as many pairwise compares as possible in parallel, rather than structuring it as a big chain of dependent computations. during "heapify" operations you're jumping around inside a heap a fair bit, which may also cause cache misses, but each bunch of children will be arranged linearly in memory, so there is a bit more signal to noise of each cache line read.
by ayende on 11/29/22, 3:14 PM
Second, it has a `O(N)` performance on inserts.
This is beyond unexpected for something that is supposed to be a queue.
by blowski on 11/29/22, 6:42 AM
I would perhaps attempt to gather more non functional requirements. How many items on the queue? How quickly are they added? How many threads are consuming from the queue? What’s the size of the message?
Also, how much would all this cost to run, in terms of memory? Is there a way of persisting the in-memory structure in case the server goes down?