Skip to content

Commit

Permalink
Flag for requestPaint (#31805)
Browse files Browse the repository at this point in the history
Will run a quick experiment for this.
  • Loading branch information
rickhanlonii authored Dec 16, 2024
1 parent e06c72f commit f7b1273
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/scheduler/src/SchedulerFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export const frameYieldMs = 5;
export const userBlockingPriorityTimeout = 250;
export const normalPriorityTimeout = 5000;
export const lowPriorityTimeout = 10000;
export const enableRequestPaint = true;
6 changes: 5 additions & 1 deletion packages/scheduler/src/__tests__/Scheduler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,6 +43,7 @@ describe('SchedulerBrowser', () => {
NormalPriority = Scheduler.unstable_NormalPriority;
requestPaint = Scheduler.unstable_requestPaint;
shouldYield = Scheduler.unstable_shouldYield;
SchedulerFeatureFlags = require('../SchedulerFeatureFlags');
});

afterEach(() => {
Expand Down Expand Up @@ -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',
]);

Expand Down
11 changes: 8 additions & 3 deletions packages/scheduler/src/forks/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
userBlockingPriorityTimeout,
lowPriorityTimeout,
normalPriorityTimeout,
enableRequestPaint,
} from '../SchedulerFeatureFlags';

import {push, pop, peek} from '../SchedulerMinHeap';
Expand Down Expand Up @@ -458,7 +459,7 @@ let frameInterval = frameYieldMs;
let startTime = -1;

function shouldYieldToHost(): boolean {
if (needsPaint) {
if (enableRequestPaint && needsPaint) {
// Yield now.
return true;
}
Expand All @@ -473,7 +474,9 @@ function shouldYieldToHost(): boolean {
}

function requestPaint() {
needsPaint = true;
if (enableRequestPaint) {
needsPaint = true;
}
}

function forceFrameRate(fps: number) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
export const userBlockingPriorityTimeout = 250;
export const normalPriorityTimeout = 5000;
export const lowPriorityTimeout = 10000;
export const enableRequestPaint = __VARIANT__;
1 change: 1 addition & 0 deletions packages/scheduler/src/forks/SchedulerFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const {
userBlockingPriorityTimeout,
normalPriorityTimeout,
lowPriorityTimeout,
enableRequestPaint,
} = dynamicFeatureFlags;

export const frameYieldMs = 10;
Expand Down

0 comments on commit f7b1273

Please sign in to comment.