Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag for requestPaint #31805

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading