You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The original logic relies on a variable remainingRounds and in order to maintain it, all timeouts in the bucket have to be traversed.
In fact, the complete traversing of the linked list is not necessary.
My idea is to introduce a new variable currRound which represent the current round of the timer, and execRound for the execution round of each timeout. currRound is added by 1 when the tick starts a new round. Then for each timeout, we compare currRound and execRound to determine if the task should be executed, and break the loop once currRound < execRound.
By this means, we can reduce the number of traversed nodes, and the performance would be especially improved when the node number is large.
The text was updated successfully, but these errors were encountered:
The original logic relies on a variable
remainingRounds
and in order to maintain it, all timeouts in the bucket have to be traversed.In fact, the complete traversing of the linked list is not necessary.
My idea is to introduce a new variable
currRound
which represent the current round of the timer, andexecRound
for the execution round of each timeout.currRound
is added by 1 when the tick starts a new round. Then for each timeout, we comparecurrRound
andexecRound
to determine if the task should be executed, and break the loop oncecurrRound
<execRound
.By this means, we can reduce the number of traversed nodes, and the performance would be especially improved when the node number is large.
The text was updated successfully, but these errors were encountered: