workers
workers copied to clipboard
Stop using a red black tree for the scheduler (SortedSet)
The existing implementation of SortedSet
(ruby 2 and 3) asks each new timer to compare to other timers at the time of insertion and then places the object in the tree so it is sorted. Well, this gem is calculating the time remaining for a timer, but it never recalculates after the value is inserted into the tree.
This implementation evaluates sec_remaining
when it accesses the set, which is required because the order is determined by that value, which changes over time. The previous implementation was not reevaluating these on insert, so the order would become more wrong over time.
The implementation of SortedSet is the ruby version from 2.x which was removed here. For large data sets it is definitely inefficient, but it is functional.