Skip to content

Commit bd83da5

Browse files
committed
[Scheduler] Store Tasks on a Min Binary Heap
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).
1 parent 75ab53b commit bd83da5

File tree

3 files changed

+170
-196
lines changed

3 files changed

+170
-196
lines changed

packages/react-dom/src/events/SimpleEventPlugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ for (let i = 0; i < eventTuples.length; i++) {
190190

191191
const config = {
192192
phasedRegistrationNames: {
193+
DOMTopLevelEventTypes,
193194
bubbled: onEvent,
194195
captured: onEvent + 'Capture',
195196
},

0 commit comments

Comments
 (0)