Skip to content

Commit f7b1273

Browse files
authored
Flag for requestPaint (facebook#31805)
Will run a quick experiment for this.
1 parent e06c72f commit f7b1273

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

packages/scheduler/src/SchedulerFeatureFlags.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export const frameYieldMs = 5;
1414
export const userBlockingPriorityTimeout = 250;
1515
export const normalPriorityTimeout = 5000;
1616
export const lowPriorityTimeout = 10000;
17+
export const enableRequestPaint = true;

packages/scheduler/src/__tests__/Scheduler-test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ let scheduleCallback;
1818
let requestPaint;
1919
let shouldYield;
2020
let NormalPriority;
21+
let SchedulerFeatureFlags;
2122

2223
// The Scheduler implementation uses browser APIs like `MessageChannel` and
2324
// `setTimeout` to schedule work on the main thread. Most of our tests treat
@@ -42,6 +43,7 @@ describe('SchedulerBrowser', () => {
4243
NormalPriority = Scheduler.unstable_NormalPriority;
4344
requestPaint = Scheduler.unstable_requestPaint;
4445
shouldYield = Scheduler.unstable_shouldYield;
46+
SchedulerFeatureFlags = require('../SchedulerFeatureFlags');
4547
});
4648

4749
afterEach(() => {
@@ -199,7 +201,9 @@ describe('SchedulerBrowser', () => {
199201
runtime.assertLog([
200202
'Message Event',
201203
'Task',
202-
'Yield at 0ms',
204+
SchedulerFeatureFlags.enableRequestPaint
205+
? 'Yield at 0ms'
206+
: `Yield at ${SchedulerFeatureFlags.frameYieldMs}ms`,
203207
'Post Message',
204208
]);
205209

packages/scheduler/src/forks/Scheduler.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
userBlockingPriorityTimeout,
1919
lowPriorityTimeout,
2020
normalPriorityTimeout,
21+
enableRequestPaint,
2122
} from '../SchedulerFeatureFlags';
2223

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

460461
function shouldYieldToHost(): boolean {
461-
if (needsPaint) {
462+
if (enableRequestPaint && needsPaint) {
462463
// Yield now.
463464
return true;
464465
}
@@ -473,7 +474,9 @@ function shouldYieldToHost(): boolean {
473474
}
474475

475476
function requestPaint() {
476-
needsPaint = true;
477+
if (enableRequestPaint) {
478+
needsPaint = true;
479+
}
477480
}
478481

479482
function forceFrameRate(fps: number) {
@@ -494,7 +497,9 @@ function forceFrameRate(fps: number) {
494497
}
495498

496499
const performWorkUntilDeadline = () => {
497-
needsPaint = false;
500+
if (enableRequestPaint) {
501+
needsPaint = false;
502+
}
498503
if (isMessageLoopRunning) {
499504
const currentTime = getCurrentTime();
500505
// Keep track of the start time so we can measure how long the main thread

packages/scheduler/src/forks/SchedulerFeatureFlags.www-dynamic.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
export const userBlockingPriorityTimeout = 250;
1515
export const normalPriorityTimeout = 5000;
1616
export const lowPriorityTimeout = 10000;
17+
export const enableRequestPaint = __VARIANT__;

packages/scheduler/src/forks/SchedulerFeatureFlags.www.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const {
1414
userBlockingPriorityTimeout,
1515
normalPriorityTimeout,
1616
lowPriorityTimeout,
17+
enableRequestPaint,
1718
} = dynamicFeatureFlags;
1819

1920
export const frameYieldMs = 10;

0 commit comments

Comments
 (0)