Skip to content

Commit 678de68

Browse files
committed
Implement requestPaint in the actual scheduler (facebook#31784)
When implementing passive effects we did a pretty massive oversight. While the passive effect is scheduled into its own scheduler task, the scheduler doesn't always yield to the browser if it has time left. That means that if you have a fast commit phase, it might try to squeeze in the passive effects in the same frame but those then might end being very heavy. We had `requestPaint()` for this but that was only implemented for the `isInputPending` experiment. It wasn't thought we needed it for the regular scheduler because it yields "every frame" anyway - but it doesn't yield every task. While the `isInputPending` experiment showed that it wasn't actually any significant impact, and it was better to keep shorter yield time anyway. Which is why we deleted the code. Whatever small win it did see in some cases might have been actually due to this issue rather than anything to do with `isInputPending` at all. As you can see in facebook#31782 we do have this implemented in the mock scheduler and a lot of behavior that we assert assumes that this works. So this just implements yielding after `requestPaint` is called. Before: <img width="1023" alt="Screenshot 2024-12-14 at 3 40 24 PM" src="https://github.com/user-attachments/assets/d60f4bb2-c8f8-4f91-a402-9ac25b278450" /> After: <img width="1108" alt="Screenshot 2024-12-14 at 3 41 25 PM" src="https://github.com/user-attachments/assets/170cdb90-a049-436f-9501-be3fb9bc04ca" /> Notice how in after the native task is split into two. It might not always actually paint and the native scheduler might make the same mistake and think it has enough time left but it's at least less likely to. We do have another way to do this. When we yield a continuation we also yield to the native browser. This is to enable the Suspense Optimization (currently disabled) to work. We could do the same for passive effects and, in fact, I have a branch that does but because that requires a lot more tests to be fixed it's a lot more invasive of a change. The nice thing about this approach is that this is not even running in tests at all and the tests we do have assert that this is the behavior already. 😬 DiffTrain build for [c80b336](facebook@c80b336)
1 parent 2a82f49 commit 678de68

40 files changed

+160
-112
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9e2c233139e62ea2f50bfa8986de02044e895c65
1+
c80b336d23aa472b5e5910268138ac0447d6ae19
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9e2c233139e62ea2f50bfa8986de02044e895c65
1+
c80b336d23aa472b5e5910268138ac0447d6ae19

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,7 @@ __DEV__ &&
19541954
exports.useTransition = function () {
19551955
return resolveDispatcher().useTransition();
19561956
};
1957-
exports.version = "19.1.0-www-classic-9e2c2331-20241214";
1957+
exports.version = "19.1.0-www-classic-c80b336d-20241214";
19581958
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
19591959
"function" ===
19601960
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,7 @@ __DEV__ &&
19541954
exports.useTransition = function () {
19551955
return resolveDispatcher().useTransition();
19561956
};
1957-
exports.version = "19.1.0-www-modern-9e2c2331-20241214";
1957+
exports.version = "19.1.0-www-modern-c80b336d-20241214";
19581958
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
19591959
"function" ===
19601960
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,4 +635,4 @@ exports.useSyncExternalStore = function (
635635
exports.useTransition = function () {
636636
return ReactSharedInternals.H.useTransition();
637637
};
638-
exports.version = "19.1.0-www-classic-9e2c2331-20241214";
638+
exports.version = "19.1.0-www-classic-c80b336d-20241214";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,4 +635,4 @@ exports.useSyncExternalStore = function (
635635
exports.useTransition = function () {
636636
return ReactSharedInternals.H.useTransition();
637637
};
638-
exports.version = "19.1.0-www-modern-9e2c2331-20241214";
638+
exports.version = "19.1.0-www-modern-c80b336d-20241214";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ exports.useSyncExternalStore = function (
639639
exports.useTransition = function () {
640640
return ReactSharedInternals.H.useTransition();
641641
};
642-
exports.version = "19.1.0-www-classic-9e2c2331-20241214";
642+
exports.version = "19.1.0-www-classic-c80b336d-20241214";
643643
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
644644
"function" ===
645645
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ exports.useSyncExternalStore = function (
639639
exports.useTransition = function () {
640640
return ReactSharedInternals.H.useTransition();
641641
};
642-
exports.version = "19.1.0-www-modern-9e2c2331-20241214";
642+
exports.version = "19.1.0-www-modern-c80b336d-20241214";
643643
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
644644
"function" ===
645645
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17189,10 +17189,10 @@ __DEV__ &&
1718917189
(function () {
1719017190
var internals = {
1719117191
bundleType: 1,
17192-
version: "19.1.0-www-classic-9e2c2331-20241214",
17192+
version: "19.1.0-www-classic-c80b336d-20241214",
1719317193
rendererPackageName: "react-art",
1719417194
currentDispatcherRef: ReactSharedInternals,
17195-
reconcilerVersion: "19.1.0-www-classic-9e2c2331-20241214"
17195+
reconcilerVersion: "19.1.0-www-classic-c80b336d-20241214"
1719617196
};
1719717197
internals.overrideHookState = overrideHookState;
1719817198
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -17226,7 +17226,7 @@ __DEV__ &&
1722617226
exports.Shape = Shape;
1722717227
exports.Surface = Surface;
1722817228
exports.Text = Text;
17229-
exports.version = "19.1.0-www-classic-9e2c2331-20241214";
17229+
exports.version = "19.1.0-www-classic-c80b336d-20241214";
1723017230
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1723117231
"function" ===
1723217232
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16952,10 +16952,10 @@ __DEV__ &&
1695216952
(function () {
1695316953
var internals = {
1695416954
bundleType: 1,
16955-
version: "19.1.0-www-modern-9e2c2331-20241214",
16955+
version: "19.1.0-www-modern-c80b336d-20241214",
1695616956
rendererPackageName: "react-art",
1695716957
currentDispatcherRef: ReactSharedInternals,
16958-
reconcilerVersion: "19.1.0-www-modern-9e2c2331-20241214"
16958+
reconcilerVersion: "19.1.0-www-modern-c80b336d-20241214"
1695916959
};
1696016960
internals.overrideHookState = overrideHookState;
1696116961
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -16989,7 +16989,7 @@ __DEV__ &&
1698916989
exports.Shape = Shape;
1699016990
exports.Surface = Surface;
1699116991
exports.Text = Text;
16992-
exports.version = "19.1.0-www-modern-9e2c2331-20241214";
16992+
exports.version = "19.1.0-www-modern-c80b336d-20241214";
1699316993
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1699416994
"function" ===
1699516995
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)