Skip to content

Commit

Permalink
Remove unused/redundant variables from Scheduler implementation (#27130)
Browse files Browse the repository at this point in the history
Tidying up some redundant code left from previous iterations of the
implementation

DiffTrain build for commit 899cb95.
  • Loading branch information
acdlite committed Jul 19, 2023
1 parent 5199045 commit 873ae21
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23982,7 +23982,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-canary-d445cee60-20230718";
var ReactVersion = "18.3.0-canary-899cb95f5-20230719";

// Might add PROFILE later.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8630,7 +8630,7 @@ var devToolsConfig$jscomp$inline_1032 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-d445cee60-20230718",
version: "18.3.0-canary-899cb95f5-20230719",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1231 = {
Expand Down Expand Up @@ -8661,7 +8661,7 @@ var internals$jscomp$inline_1231 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-d445cee60-20230718"
reconcilerVersion: "18.3.0-canary-899cb95f5-20230719"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1232 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9056,7 +9056,7 @@ var devToolsConfig$jscomp$inline_1074 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-d445cee60-20230718",
version: "18.3.0-canary-899cb95f5-20230719",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1272 = {
Expand Down Expand Up @@ -9087,7 +9087,7 @@ var internals$jscomp$inline_1272 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-d445cee60-20230718"
reconcilerVersion: "18.3.0-canary-899cb95f5-20230719"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1273 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-canary-d445cee60-20230718";
var ReactVersion = "18.3.0-canary-899cb95f5-20230719";

// ATTENTION
// When adding new symbols to this file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,4 +616,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-d445cee60-20230718";
exports.version = "18.3.0-canary-899cb95f5-20230719";
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-d445cee60-20230718";
exports.version = "18.3.0-canary-899cb95f5-20230719";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<b85c2a10b2dc93deb1fb229aeda66768>>
* @generated SignedSource<<bf6139f486580812339baacd8463bb4a>>
*/

'use strict';
Expand Down Expand Up @@ -205,7 +205,7 @@ function handleTimeout(currentTime) {
if (!isHostCallbackScheduled) {
if (peek(taskQueue) !== null) {
isHostCallbackScheduled = true;
requestHostCallback(flushWork);
requestHostCallback();
} else {
var firstTimer = peek(timerQueue);

Expand All @@ -216,7 +216,7 @@ function handleTimeout(currentTime) {
}
}

function flushWork(hasTimeRemaining, initialTime) {
function flushWork(initialTime) {
isHostCallbackScheduled = false;

if (isHostTimeoutScheduled) {
Expand All @@ -233,7 +233,7 @@ function flushWork(hasTimeRemaining, initialTime) {
if (enableProfiling);
else {
// No catch in prod code path.
return workLoop(hasTimeRemaining, initialTime);
return workLoop(initialTime);
}
} finally {
currentTask = null;
Expand All @@ -242,16 +242,13 @@ function flushWork(hasTimeRemaining, initialTime) {
}
}

function workLoop(hasTimeRemaining, initialTime) {
function workLoop(initialTime) {
var currentTime = initialTime;
advanceTimers(currentTime);
currentTask = peek(taskQueue);

while (currentTask !== null && !enableSchedulerDebugging) {
if (
currentTask.expirationTime > currentTime &&
(!hasTimeRemaining || shouldYieldToHost())
) {
if (currentTask.expirationTime > currentTime && shouldYieldToHost()) {
// This currentTask hasn't expired, and we've reached the deadline.
break;
} // $FlowFixMe[incompatible-use] found when upgrading Flow
Expand Down Expand Up @@ -445,7 +442,7 @@ function unstable_scheduleCallback(priorityLevel, callback, options) {

if (!isHostCallbackScheduled && !isPerformingWork) {
isHostCallbackScheduled = true;
requestHostCallback(flushWork);
requestHostCallback();
}
}

Expand All @@ -457,7 +454,7 @@ function unstable_pauseExecution() {}
function unstable_continueExecution() {
if (!isHostCallbackScheduled && !isPerformingWork) {
isHostCallbackScheduled = true;
requestHostCallback(flushWork);
requestHostCallback();
}
}

Expand All @@ -477,7 +474,6 @@ function unstable_getCurrentPriorityLevel() {
}

var isMessageLoopRunning = false;
var scheduledHostCallback = null;
var taskTimeoutID = -1; // Scheduler periodically yields in case there is other work on the main
// thread, like user events. By default, it yields multiple times per frame.
// It does not attempt to align with frame boundaries, since most tasks don't
Expand Down Expand Up @@ -519,35 +515,30 @@ function forceFrameRate(fps) {
}

var performWorkUntilDeadline = function () {
if (scheduledHostCallback !== null) {
if (isMessageLoopRunning) {
var currentTime = exports.unstable_now(); // Keep track of the start time so we can measure how long the main thread
// has been blocked.

startTime = currentTime;
var hasTimeRemaining = true; // If a scheduler task throws, exit the current browser task so the
startTime = currentTime; // If a scheduler task throws, exit the current browser task so the
// error can be observed.
//
// Intentionally not using a try-catch, since that makes some debugging
// techniques harder. Instead, if `scheduledHostCallback` errors, then
// `hasMoreWork` will remain true, and we'll continue the work loop.
// techniques harder. Instead, if `flushWork` errors, then `hasMoreWork` will
// remain true, and we'll continue the work loop.

var hasMoreWork = true;

try {
// $FlowFixMe[not-a-function] found when upgrading Flow
hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
hasMoreWork = flushWork(currentTime);
} finally {
if (hasMoreWork) {
// If there's more work, schedule the next message event at the end
// of the preceding one.
schedulePerformWorkUntilDeadline();
} else {
isMessageLoopRunning = false;
scheduledHostCallback = null;
}
}
} else {
isMessageLoopRunning = false;
} // Yielding to the browser will give it a chance to paint, so we can
};

Expand Down Expand Up @@ -587,8 +578,6 @@ if (typeof localSetImmediate === "function") {
}

function requestHostCallback(callback) {
scheduledHostCallback = callback;

if (!isMessageLoopRunning) {
isMessageLoopRunning = true;
schedulePerformWorkUntilDeadline();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<6de9b4c616b4fa4d342cccd7689eb2af>>
* @generated SignedSource<<cd7ed3a069445a95189053c07769d208>>
*/

"use strict";
Expand Down Expand Up @@ -104,86 +104,89 @@ function handleTimeout(currentTime) {
advanceTimers(currentTime);
if (!isHostCallbackScheduled)
if (null !== peek(taskQueue))
(isHostCallbackScheduled = !0), requestHostCallback(flushWork);
(isHostCallbackScheduled = !0), requestHostCallback();
else {
var firstTimer = peek(timerQueue);
null !== firstTimer &&
requestHostTimeout(handleTimeout, firstTimer.startTime - currentTime);
}
}
function flushWork(hasTimeRemaining, initialTime) {
isHostCallbackScheduled = !1;
isHostTimeoutScheduled &&
((isHostTimeoutScheduled = !1),
localClearTimeout(taskTimeoutID),
(taskTimeoutID = -1));
isPerformingWork = !0;
var previousPriorityLevel = currentPriorityLevel;
try {
a: {
advanceTimers(initialTime);
for (
currentTask = peek(taskQueue);
null !== currentTask &&
(!(currentTask.expirationTime > initialTime) ||
(hasTimeRemaining && !shouldYieldToHost()));

) {
var callback = currentTask.callback;
if ("function" === typeof callback) {
currentTask.callback = null;
currentPriorityLevel = currentTask.priorityLevel;
var continuationCallback = callback(
currentTask.expirationTime <= initialTime
);
initialTime = exports.unstable_now();
if ("function" === typeof continuationCallback) {
currentTask.callback = continuationCallback;
advanceTimers(initialTime);
var JSCompiler_inline_result = !0;
break a;
} else
currentTask === peek(taskQueue) && pop(taskQueue),
advanceTimers(initialTime);
} else pop(taskQueue);
currentTask = peek(taskQueue);
}
if (null !== currentTask) JSCompiler_inline_result = !0;
else {
var firstTimer = peek(timerQueue);
null !== firstTimer &&
requestHostTimeout(handleTimeout, firstTimer.startTime - initialTime);
JSCompiler_inline_result = !1;
}
}
return JSCompiler_inline_result;
} finally {
(currentTask = null),
(currentPriorityLevel = previousPriorityLevel),
(isPerformingWork = !1);
}
}
var isMessageLoopRunning = !1,
scheduledHostCallback = null,
taskTimeoutID = -1,
frameInterval = 5,
startTime = -1;
function shouldYieldToHost() {
return exports.unstable_now() - startTime < frameInterval ? !1 : !0;
}
function performWorkUntilDeadline() {
if (null !== scheduledHostCallback) {
if (isMessageLoopRunning) {
var currentTime = exports.unstable_now();
startTime = currentTime;
var hasMoreWork = !0;
try {
hasMoreWork = scheduledHostCallback(!0, currentTime);
a: {
isHostCallbackScheduled = !1;
isHostTimeoutScheduled &&
((isHostTimeoutScheduled = !1),
localClearTimeout(taskTimeoutID),
(taskTimeoutID = -1));
isPerformingWork = !0;
var previousPriorityLevel = currentPriorityLevel;
try {
b: {
advanceTimers(currentTime);
for (
currentTask = peek(taskQueue);
null !== currentTask &&
!(
currentTask.expirationTime > currentTime && shouldYieldToHost()
);

) {
var callback = currentTask.callback;
if ("function" === typeof callback) {
currentTask.callback = null;
currentPriorityLevel = currentTask.priorityLevel;
var continuationCallback = callback(
currentTask.expirationTime <= currentTime
);
currentTime = exports.unstable_now();
if ("function" === typeof continuationCallback) {
currentTask.callback = continuationCallback;
advanceTimers(currentTime);
hasMoreWork = !0;
break b;
}
currentTask === peek(taskQueue) && pop(taskQueue);
advanceTimers(currentTime);
} else pop(taskQueue);
currentTask = peek(taskQueue);
}
if (null !== currentTask) hasMoreWork = !0;
else {
var firstTimer = peek(timerQueue);
null !== firstTimer &&
requestHostTimeout(
handleTimeout,
firstTimer.startTime - currentTime
);
hasMoreWork = !1;
}
}
break a;
} finally {
(currentTask = null),
(currentPriorityLevel = previousPriorityLevel),
(isPerformingWork = !1);
}
hasMoreWork = void 0;
}
} finally {
hasMoreWork
? schedulePerformWorkUntilDeadline()
: ((isMessageLoopRunning = !1), (scheduledHostCallback = null));
: (isMessageLoopRunning = !1);
}
} else isMessageLoopRunning = !1;
}
}
var schedulePerformWorkUntilDeadline;
if ("function" === typeof localSetImmediate)
Expand All @@ -201,8 +204,7 @@ else if ("undefined" !== typeof MessageChannel) {
schedulePerformWorkUntilDeadline = function () {
localSetTimeout(performWorkUntilDeadline, 0);
};
function requestHostCallback(callback) {
scheduledHostCallback = callback;
function requestHostCallback() {
isMessageLoopRunning ||
((isMessageLoopRunning = !0), schedulePerformWorkUntilDeadline());
}
Expand All @@ -223,7 +225,7 @@ exports.unstable_cancelCallback = function (task) {
exports.unstable_continueExecution = function () {
isHostCallbackScheduled ||
isPerformingWork ||
((isHostCallbackScheduled = !0), requestHostCallback(flushWork));
((isHostCallbackScheduled = !0), requestHostCallback());
};
exports.unstable_forceFrameRate = function (fps) {
0 > fps || 125 < fps
Expand Down Expand Up @@ -328,7 +330,7 @@ exports.unstable_scheduleCallback = function (
push(taskQueue, priorityLevel),
isHostCallbackScheduled ||
isPerformingWork ||
((isHostCallbackScheduled = !0), requestHostCallback(flushWork)));
((isHostCallbackScheduled = !0), requestHostCallback()));
return priorityLevel;
};
exports.unstable_shouldYield = shouldYieldToHost;
Expand Down
Loading

0 comments on commit 873ae21

Please sign in to comment.