I was trying to improve performance of JITDB, and I noticed some calls to this library that could be improved.
The kSmallest method seemed to be running unusually slowly compared with other methods in this library. While the overall algorithm looked sound, it didn't seem to stand up to empirical testing & I found more success by simply cloning the inner array and dequeuing elements from it. I calculated an upper bound on how many elements to clone based on how deep kSmallest may need to look in the heap for results.
I updated clone while I was at it. The change from push to slice should take better advantage of JS engine optimizations for the initial copy, though I can't speak to whether the resulting array will be considered "packed" or "holey".
I was trying to improve performance of JITDB, and I noticed some calls to this library that could be improved.
The
kSmallest
method seemed to be running unusually slowly compared with other methods in this library. While the overall algorithm looked sound, it didn't seem to stand up to empirical testing & I found more success by simply cloning the inner array and dequeuing elements from it. I calculated an upper bound on how many elements to clone based on how deepkSmallest
may need to look in the heap for results.I updated
clone
while I was at it. The change frompush
toslice
should take better advantage of JS engine optimizations for the initial copy, though I can't speak to whether the resulting array will be considered "packed" or "holey".