mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
35ef78de3e
Adds a `delay` option to `scheduleCallback`. When specified, the task is not scheduled until after the delay has elapsed. Delayed tasks are scheduled on a timer queue maintained by Scheduler, instead of directly with the browser. The main benefit is to reduce the number of native browser timers that Scheduler's `message` event handler has to contend with; so, after yielding to the browser at the end of the frame, Scheduler will more quickly regain control of the main thread. Because we're able to flush the timer queue without yielding to browser timer events, there's also less task switching overhead (though in the absence of `isInputPending`, this is mostly a theoretical win since we yield every frame regardless). If the queue of non-delayed tasks is non-empty — that is, if there is pending CPU bound work — Scheduler is able to avoid a browser timer entirely by periodically checking its own timer queue while flushing tasks (inside the `message` event handler). Once the CPU-bound work is complete, if there are still pending delayed tasks, Scheduler will schedule a single browser timer that fires once the earliest delay has elapsed.