futures-timer icon indicating copy to clipboard operation
futures-timer copied to clipboard

Optimise the heap data structure.

Open Ben-PH opened this issue 5 years ago • 0 comments

I'm not familiar enough with this projects finer details and intent behind src/native/heap.rs, so my assumptions may be a bit off. I have, however, recently been doing some work that looks to me like it relates quite closely with this implementation: A heap backed priority queue with removal of arbitrary entry.

To start, it's commented that things aren't optimised. I would like to discuss how I might bring in some optimizations I have in mind.

  • I can see that the heaps sink/swim functions are manually defined. If you compare it with std-lib implementation, it has an interesting use of a data struct with custom Drops, which seems to improve things through minimizing movement of values in memory. I'd like to try and tap into the std-lib implementation, otherwise port it in and see if it improves things.
  • The heap appears to be an array of references into a linked list. The linked list itself is likely to have cache-unfriendly memory layout. The change I have in mind allows for cache-friendly arrays.
  • It looks like entries are identified by index. A change I have in mind should allow indexing to be kept, and also allow for lookup by unique id based on hash-map lookup: O(1)~

I would like to discuss these things in more detail before I get started, so I keep within the design intent of the system.

Ben-PH avatar Mar 14 '20 05:03 Ben-PH