Skip to content

Commit 9509de9

Browse files
committed
clean up isInputPending in Scheduler (#28444)
## Summary `isInputPending` is not in use. This PR cleans up the flags controlling its gating and parameters to simplify Scheduler. Makes `frameYieldMs` feature flag static, set to 10ms in www, which we found built on the wins provided by a broader yield interval via `isInputPending`. Flag remains set to 5ms in OSS builds. ## How did you test this change? `yarn test Scheduler` DiffTrain build for [3bcd2de](3bcd2de)
1 parent b29a80f commit 9509de9

11 files changed

+43
-291
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2f240c91ed54900adee213565cb2039e161629e9
1+
3bcd2de01b5716202eabe8faa338f51bdc59ce26

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,4 +617,4 @@ exports.useSyncExternalStore = function (
617617
exports.useTransition = function () {
618618
return ReactCurrentDispatcher.current.useTransition();
619619
};
620-
exports.version = "18.3.0-www-modern-e541e76b";
620+
exports.version = "18.3.0-www-modern-29517cf7";

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ exports.useSyncExternalStore = function (
621621
exports.useTransition = function () {
622622
return ReactCurrentDispatcher.current.useTransition();
623623
};
624-
exports.version = "18.3.0-www-modern-4a897bb7";
624+
exports.version = "18.3.0-www-modern-9c6d816f";
625625
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
626626
"function" ===
627627
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/Scheduler-dev.classic.js

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,8 @@ if (__DEV__) {
3131
var userBlockingPriorityTimeout =
3232
dynamicFeatureFlags.userBlockingPriorityTimeout,
3333
normalPriorityTimeout = dynamicFeatureFlags.normalPriorityTimeout,
34-
lowPriorityTimeout = dynamicFeatureFlags.lowPriorityTimeout,
35-
enableIsInputPending = dynamicFeatureFlags.enableIsInputPending,
36-
enableIsInputPendingContinuous =
37-
dynamicFeatureFlags.enableIsInputPendingContinuous,
38-
frameYieldMs = dynamicFeatureFlags.frameYieldMs,
39-
continuousYieldMs = dynamicFeatureFlags.continuousYieldMs,
40-
maxYieldMs = dynamicFeatureFlags.maxYieldMs;
34+
lowPriorityTimeout = dynamicFeatureFlags.lowPriorityTimeout;
35+
var frameYieldMs = 10;
4136
var enableProfiling = enableProfilingFeatureFlag;
4237

4338
function push(heap, node) {
@@ -297,16 +292,6 @@ if (__DEV__) {
297292
var localSetImmediate =
298293
typeof setImmediate !== "undefined" ? setImmediate : null; // IE and Node.js + jsdom
299294

300-
var isInputPending =
301-
typeof navigator !== "undefined" && // $FlowFixMe[prop-missing]
302-
navigator.scheduling !== undefined && // $FlowFixMe[incompatible-type]
303-
navigator.scheduling.isInputPending !== undefined
304-
? navigator.scheduling.isInputPending.bind(navigator.scheduling)
305-
: null;
306-
var continuousOptions = {
307-
includeContinuous: enableIsInputPendingContinuous
308-
};
309-
310295
function advanceTimers(currentTime) {
311296
// Check for tasks that are no longer delayed and add them to the queue.
312297
var timer = peek(timerQueue);
@@ -684,10 +669,7 @@ if (__DEV__) {
684669
// need to be frame aligned; for those that do, use requestAnimationFrame.
685670

686671
var frameInterval = frameYieldMs;
687-
var continuousInputInterval = continuousYieldMs;
688-
var maxInterval = maxYieldMs;
689672
var startTime = -1;
690-
var needsPaint = false;
691673

692674
function shouldYieldToHost() {
693675
var timeElapsed = exports.unstable_now() - startTime;
@@ -696,54 +678,12 @@ if (__DEV__) {
696678
// The main thread has only been blocked for a really short amount of time;
697679
// smaller than a single frame. Don't yield yet.
698680
return false;
699-
} // The main thread has been blocked for a non-negligible amount of time. We
700-
// may want to yield control of the main thread, so the browser can perform
701-
// high priority tasks. The main ones are painting and user input. If there's
702-
// a pending paint or a pending input, then we should yield. But if there's
703-
// neither, then we can yield less often while remaining responsive. We'll
704-
// eventually yield regardless, since there could be a pending paint that
705-
// wasn't accompanied by a call to `requestPaint`, or other main thread tasks
706-
// like network events.
707-
708-
if (enableIsInputPending) {
709-
if (needsPaint) {
710-
// There's a pending paint (signaled by `requestPaint`). Yield now.
711-
return true;
712-
}
713-
714-
if (timeElapsed < continuousInputInterval) {
715-
// We haven't blocked the thread for that long. Only yield if there's a
716-
// pending discrete input (e.g. click). It's OK if there's pending
717-
// continuous input (e.g. mouseover).
718-
if (isInputPending !== null) {
719-
return isInputPending();
720-
}
721-
} else if (timeElapsed < maxInterval) {
722-
// Yield if there's either a pending discrete or continuous input.
723-
if (isInputPending !== null) {
724-
return isInputPending(continuousOptions);
725-
}
726-
} else {
727-
// We've blocked the thread for a long time. Even if there's no pending
728-
// input, there may be some other scheduled work that we don't know about,
729-
// like a network event. Yield now.
730-
return true;
731-
}
732-
} // `isInputPending` isn't available. Yield now.
681+
} // Yield now.
733682

734683
return true;
735684
}
736685

737-
function requestPaint() {
738-
if (
739-
enableIsInputPending &&
740-
navigator !== undefined && // $FlowFixMe[prop-missing]
741-
navigator.scheduling !== undefined && // $FlowFixMe[incompatible-type]
742-
navigator.scheduling.isInputPending !== undefined
743-
) {
744-
needsPaint = true;
745-
} // Since we yield every frame regardless, `requestPaint` has no effect.
746-
}
686+
function requestPaint() {}
747687

748688
function forceFrameRate(fps) {
749689
if (fps < 0 || fps > 125) {
@@ -788,10 +728,7 @@ if (__DEV__) {
788728
isMessageLoopRunning = false;
789729
}
790730
}
791-
} // Yielding to the browser will give it a chance to paint, so we can
792-
// reset this.
793-
794-
needsPaint = false;
731+
}
795732
};
796733

797734
var schedulePerformWorkUntilDeadline;

compiled/facebook-www/Scheduler-dev.modern.js

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,8 @@ if (__DEV__) {
3131
var userBlockingPriorityTimeout =
3232
dynamicFeatureFlags.userBlockingPriorityTimeout,
3333
normalPriorityTimeout = dynamicFeatureFlags.normalPriorityTimeout,
34-
lowPriorityTimeout = dynamicFeatureFlags.lowPriorityTimeout,
35-
enableIsInputPending = dynamicFeatureFlags.enableIsInputPending,
36-
enableIsInputPendingContinuous =
37-
dynamicFeatureFlags.enableIsInputPendingContinuous,
38-
frameYieldMs = dynamicFeatureFlags.frameYieldMs,
39-
continuousYieldMs = dynamicFeatureFlags.continuousYieldMs,
40-
maxYieldMs = dynamicFeatureFlags.maxYieldMs;
34+
lowPriorityTimeout = dynamicFeatureFlags.lowPriorityTimeout;
35+
var frameYieldMs = 10;
4136
var enableProfiling = enableProfilingFeatureFlag;
4237

4338
function push(heap, node) {
@@ -297,16 +292,6 @@ if (__DEV__) {
297292
var localSetImmediate =
298293
typeof setImmediate !== "undefined" ? setImmediate : null; // IE and Node.js + jsdom
299294

300-
var isInputPending =
301-
typeof navigator !== "undefined" && // $FlowFixMe[prop-missing]
302-
navigator.scheduling !== undefined && // $FlowFixMe[incompatible-type]
303-
navigator.scheduling.isInputPending !== undefined
304-
? navigator.scheduling.isInputPending.bind(navigator.scheduling)
305-
: null;
306-
var continuousOptions = {
307-
includeContinuous: enableIsInputPendingContinuous
308-
};
309-
310295
function advanceTimers(currentTime) {
311296
// Check for tasks that are no longer delayed and add them to the queue.
312297
var timer = peek(timerQueue);
@@ -684,10 +669,7 @@ if (__DEV__) {
684669
// need to be frame aligned; for those that do, use requestAnimationFrame.
685670

686671
var frameInterval = frameYieldMs;
687-
var continuousInputInterval = continuousYieldMs;
688-
var maxInterval = maxYieldMs;
689672
var startTime = -1;
690-
var needsPaint = false;
691673

692674
function shouldYieldToHost() {
693675
var timeElapsed = exports.unstable_now() - startTime;
@@ -696,54 +678,12 @@ if (__DEV__) {
696678
// The main thread has only been blocked for a really short amount of time;
697679
// smaller than a single frame. Don't yield yet.
698680
return false;
699-
} // The main thread has been blocked for a non-negligible amount of time. We
700-
// may want to yield control of the main thread, so the browser can perform
701-
// high priority tasks. The main ones are painting and user input. If there's
702-
// a pending paint or a pending input, then we should yield. But if there's
703-
// neither, then we can yield less often while remaining responsive. We'll
704-
// eventually yield regardless, since there could be a pending paint that
705-
// wasn't accompanied by a call to `requestPaint`, or other main thread tasks
706-
// like network events.
707-
708-
if (enableIsInputPending) {
709-
if (needsPaint) {
710-
// There's a pending paint (signaled by `requestPaint`). Yield now.
711-
return true;
712-
}
713-
714-
if (timeElapsed < continuousInputInterval) {
715-
// We haven't blocked the thread for that long. Only yield if there's a
716-
// pending discrete input (e.g. click). It's OK if there's pending
717-
// continuous input (e.g. mouseover).
718-
if (isInputPending !== null) {
719-
return isInputPending();
720-
}
721-
} else if (timeElapsed < maxInterval) {
722-
// Yield if there's either a pending discrete or continuous input.
723-
if (isInputPending !== null) {
724-
return isInputPending(continuousOptions);
725-
}
726-
} else {
727-
// We've blocked the thread for a long time. Even if there's no pending
728-
// input, there may be some other scheduled work that we don't know about,
729-
// like a network event. Yield now.
730-
return true;
731-
}
732-
} // `isInputPending` isn't available. Yield now.
681+
} // Yield now.
733682

734683
return true;
735684
}
736685

737-
function requestPaint() {
738-
if (
739-
enableIsInputPending &&
740-
navigator !== undefined && // $FlowFixMe[prop-missing]
741-
navigator.scheduling !== undefined && // $FlowFixMe[incompatible-type]
742-
navigator.scheduling.isInputPending !== undefined
743-
) {
744-
needsPaint = true;
745-
} // Since we yield every frame regardless, `requestPaint` has no effect.
746-
}
686+
function requestPaint() {}
747687

748688
function forceFrameRate(fps) {
749689
if (fps < 0 || fps > 125) {
@@ -788,10 +728,7 @@ if (__DEV__) {
788728
isMessageLoopRunning = false;
789729
}
790730
}
791-
} // Yielding to the browser will give it a chance to paint, so we can
792-
// reset this.
793-
794-
needsPaint = false;
731+
}
795732
};
796733

797734
var schedulePerformWorkUntilDeadline;

compiled/facebook-www/Scheduler-prod.classic.js

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@
1414
var dynamicFeatureFlags = require("SchedulerFeatureFlags"),
1515
userBlockingPriorityTimeout = dynamicFeatureFlags.userBlockingPriorityTimeout,
1616
normalPriorityTimeout = dynamicFeatureFlags.normalPriorityTimeout,
17-
lowPriorityTimeout = dynamicFeatureFlags.lowPriorityTimeout,
18-
enableIsInputPending = dynamicFeatureFlags.enableIsInputPending,
19-
enableIsInputPendingContinuous =
20-
dynamicFeatureFlags.enableIsInputPendingContinuous,
21-
frameYieldMs = dynamicFeatureFlags.frameYieldMs,
22-
continuousYieldMs = dynamicFeatureFlags.continuousYieldMs,
23-
maxYieldMs = dynamicFeatureFlags.maxYieldMs;
17+
lowPriorityTimeout = dynamicFeatureFlags.lowPriorityTimeout;
2418
function push(heap, node) {
2519
var index = heap.length;
2620
heap.push(node);
@@ -93,14 +87,7 @@ var taskQueue = [],
9387
isHostTimeoutScheduled = !1,
9488
localSetTimeout = "function" === typeof setTimeout ? setTimeout : null,
9589
localClearTimeout = "function" === typeof clearTimeout ? clearTimeout : null,
96-
localSetImmediate = "undefined" !== typeof setImmediate ? setImmediate : null,
97-
isInputPending =
98-
"undefined" !== typeof navigator &&
99-
void 0 !== navigator.scheduling &&
100-
void 0 !== navigator.scheduling.isInputPending
101-
? navigator.scheduling.isInputPending.bind(navigator.scheduling)
102-
: null,
103-
continuousOptions = { includeContinuous: enableIsInputPendingContinuous };
90+
localSetImmediate = "undefined" !== typeof setImmediate ? setImmediate : null;
10491
function advanceTimers(currentTime) {
10592
for (var timer = peek(timerQueue); null !== timer; ) {
10693
if (null === timer.callback) pop(timerQueue);
@@ -126,20 +113,10 @@ function handleTimeout(currentTime) {
126113
}
127114
var isMessageLoopRunning = !1,
128115
taskTimeoutID = -1,
129-
frameInterval = frameYieldMs,
130-
startTime = -1,
131-
needsPaint = !1;
116+
frameInterval = 10,
117+
startTime = -1;
132118
function shouldYieldToHost() {
133-
var timeElapsed = exports.unstable_now() - startTime;
134-
if (timeElapsed < frameInterval) return !1;
135-
if (enableIsInputPending) {
136-
if (needsPaint) return !0;
137-
if (timeElapsed < continuousYieldMs) {
138-
if (null !== isInputPending) return isInputPending();
139-
} else if (timeElapsed < maxYieldMs && null !== isInputPending)
140-
return isInputPending(continuousOptions);
141-
}
142-
return !0;
119+
return exports.unstable_now() - startTime < frameInterval ? !1 : !0;
143120
}
144121
function performWorkUntilDeadline() {
145122
if (isMessageLoopRunning) {
@@ -212,7 +189,6 @@ function performWorkUntilDeadline() {
212189
: (isMessageLoopRunning = !1);
213190
}
214191
}
215-
needsPaint = !1;
216192
}
217193
var schedulePerformWorkUntilDeadline;
218194
if ("function" === typeof localSetImmediate)
@@ -259,7 +235,7 @@ exports.unstable_forceFrameRate = function (fps) {
259235
? console.error(
260236
"forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"
261237
)
262-
: (frameInterval = 0 < fps ? Math.floor(1e3 / fps) : frameYieldMs);
238+
: (frameInterval = 0 < fps ? Math.floor(1e3 / fps) : 10);
263239
};
264240
exports.unstable_getCurrentPriorityLevel = function () {
265241
return currentPriorityLevel;
@@ -288,13 +264,7 @@ exports.unstable_next = function (eventHandler) {
288264
exports.unstable_pauseExecution = function () {
289265
isSchedulerPaused = !0;
290266
};
291-
exports.unstable_requestPaint = function () {
292-
enableIsInputPending &&
293-
void 0 !== navigator &&
294-
void 0 !== navigator.scheduling &&
295-
void 0 !== navigator.scheduling.isInputPending &&
296-
(needsPaint = !0);
297-
};
267+
exports.unstable_requestPaint = function () {};
298268
exports.unstable_runWithPriority = function (priorityLevel, eventHandler) {
299269
switch (priorityLevel) {
300270
case 1:

0 commit comments

Comments
 (0)