Skip to content

Commit

Permalink
[Scheduler] Store Tasks on a Min Binary Heap
Browse files Browse the repository at this point in the history
Switches Scheduler's priority queue implementation (for both tasks and
timers) to an array-based min binary heap.

This replaces the naive linked-list implementation that was left over
from the queue we once used to schedule React roots. A list was arguably
fine when it was only used for roots, since the total number of roots is
usually small, and is only 1 in the common case of a single-page app.

Since Scheduler is now used for many types of JavaScript tasks (e.g.
including timers), the total number of tasks can be much larger.

Binary heaps are the standard way to implement priority queues.
Insertion is O(1) in the average case (append to the end) and O(log n)
in the worst. Deletion is O(log n). Peek is O(1).
  • Loading branch information
acdlite committed Jul 29, 2019
1 parent 75ab53b commit bd83da5
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 196 deletions.
1 change: 1 addition & 0 deletions packages/react-dom/src/events/SimpleEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ for (let i = 0; i < eventTuples.length; i++) {

const config = {
phasedRegistrationNames: {
DOMTopLevelEventTypes,
bubbled: onEvent,
captured: onEvent + 'Capture',
},
Expand Down

0 comments on commit bd83da5

Please sign in to comment.