From f7b1273da2c96057d3908f52f8587379d4418f66 Mon Sep 17 00:00:00 2001 From: Ricky Date: Mon, 16 Dec 2024 11:18:03 -0500 Subject: [PATCH] Flag for requestPaint (#31805) Will run a quick experiment for this. --- packages/scheduler/src/SchedulerFeatureFlags.js | 1 + packages/scheduler/src/__tests__/Scheduler-test.js | 6 +++++- packages/scheduler/src/forks/Scheduler.js | 11 ++++++++--- .../src/forks/SchedulerFeatureFlags.www-dynamic.js | 1 + .../scheduler/src/forks/SchedulerFeatureFlags.www.js | 1 + 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/scheduler/src/SchedulerFeatureFlags.js b/packages/scheduler/src/SchedulerFeatureFlags.js index c86de5e35dc2a..08a0d979b621b 100644 --- a/packages/scheduler/src/SchedulerFeatureFlags.js +++ b/packages/scheduler/src/SchedulerFeatureFlags.js @@ -14,3 +14,4 @@ export const frameYieldMs = 5; export const userBlockingPriorityTimeout = 250; export const normalPriorityTimeout = 5000; export const lowPriorityTimeout = 10000; +export const enableRequestPaint = true; diff --git a/packages/scheduler/src/__tests__/Scheduler-test.js b/packages/scheduler/src/__tests__/Scheduler-test.js index 9e0813e461e61..fee1216d15730 100644 --- a/packages/scheduler/src/__tests__/Scheduler-test.js +++ b/packages/scheduler/src/__tests__/Scheduler-test.js @@ -18,6 +18,7 @@ let scheduleCallback; let requestPaint; let shouldYield; let NormalPriority; +let SchedulerFeatureFlags; // The Scheduler implementation uses browser APIs like `MessageChannel` and // `setTimeout` to schedule work on the main thread. Most of our tests treat @@ -42,6 +43,7 @@ describe('SchedulerBrowser', () => { NormalPriority = Scheduler.unstable_NormalPriority; requestPaint = Scheduler.unstable_requestPaint; shouldYield = Scheduler.unstable_shouldYield; + SchedulerFeatureFlags = require('../SchedulerFeatureFlags'); }); afterEach(() => { @@ -199,7 +201,9 @@ describe('SchedulerBrowser', () => { runtime.assertLog([ 'Message Event', 'Task', - 'Yield at 0ms', + SchedulerFeatureFlags.enableRequestPaint + ? 'Yield at 0ms' + : `Yield at ${SchedulerFeatureFlags.frameYieldMs}ms`, 'Post Message', ]); diff --git a/packages/scheduler/src/forks/Scheduler.js b/packages/scheduler/src/forks/Scheduler.js index 0e85e0a99b7b0..68149a9fec14e 100644 --- a/packages/scheduler/src/forks/Scheduler.js +++ b/packages/scheduler/src/forks/Scheduler.js @@ -18,6 +18,7 @@ import { userBlockingPriorityTimeout, lowPriorityTimeout, normalPriorityTimeout, + enableRequestPaint, } from '../SchedulerFeatureFlags'; import {push, pop, peek} from '../SchedulerMinHeap'; @@ -458,7 +459,7 @@ let frameInterval = frameYieldMs; let startTime = -1; function shouldYieldToHost(): boolean { - if (needsPaint) { + if (enableRequestPaint && needsPaint) { // Yield now. return true; } @@ -473,7 +474,9 @@ function shouldYieldToHost(): boolean { } function requestPaint() { - needsPaint = true; + if (enableRequestPaint) { + needsPaint = true; + } } function forceFrameRate(fps: number) { @@ -494,7 +497,9 @@ function forceFrameRate(fps: number) { } const performWorkUntilDeadline = () => { - needsPaint = false; + if (enableRequestPaint) { + needsPaint = false; + } if (isMessageLoopRunning) { const currentTime = getCurrentTime(); // Keep track of the start time so we can measure how long the main thread diff --git a/packages/scheduler/src/forks/SchedulerFeatureFlags.www-dynamic.js b/packages/scheduler/src/forks/SchedulerFeatureFlags.www-dynamic.js index 8bbe8385b7f63..9346663083bc6 100644 --- a/packages/scheduler/src/forks/SchedulerFeatureFlags.www-dynamic.js +++ b/packages/scheduler/src/forks/SchedulerFeatureFlags.www-dynamic.js @@ -14,3 +14,4 @@ export const userBlockingPriorityTimeout = 250; export const normalPriorityTimeout = 5000; export const lowPriorityTimeout = 10000; +export const enableRequestPaint = __VARIANT__; diff --git a/packages/scheduler/src/forks/SchedulerFeatureFlags.www.js b/packages/scheduler/src/forks/SchedulerFeatureFlags.www.js index 5c42786c94d42..ec8498ec6adb5 100644 --- a/packages/scheduler/src/forks/SchedulerFeatureFlags.www.js +++ b/packages/scheduler/src/forks/SchedulerFeatureFlags.www.js @@ -14,6 +14,7 @@ export const { userBlockingPriorityTimeout, normalPriorityTimeout, lowPriorityTimeout, + enableRequestPaint, } = dynamicFeatureFlags; export const frameYieldMs = 10;