Skip to content

Commit

Permalink
Implement requestPaint in the actual scheduler (facebook#31784)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
pull[bot] committed Dec 15, 2024
1 parent d42f100 commit cba1fef
Show file tree
Hide file tree
Showing 26 changed files with 125 additions and 101 deletions.
2 changes: 1 addition & 1 deletion compiled-rn/VERSION_NATIVE_FB
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19.1.0-native-fb-9e2c2331-20241214
19.1.0-native-fb-c80b336d-20241214
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<7291728f480390b2252debc84f6fea00>>
* @generated SignedSource<<b04d7e4586e35d0745cc706e21d118d8>>
*/

"use strict";
Expand Down Expand Up @@ -420,5 +420,5 @@ __DEV__ &&
exports.useFormStatus = function () {
return resolveDispatcher().useHostTransitionStatus();
};
exports.version = "19.1.0-native-fb-9e2c2331-20241214";
exports.version = "19.1.0-native-fb-c80b336d-20241214";
})();
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<750b2d06666d3559337bd9db530269cf>>
* @generated SignedSource<<f0bcb042fc8317d7226f720e52e855bc>>
*/

"use strict";
Expand Down Expand Up @@ -203,4 +203,4 @@ exports.useFormState = function (action, initialState, permalink) {
exports.useFormStatus = function () {
return ReactSharedInternals.H.useHostTransitionStatus();
};
exports.version = "19.1.0-native-fb-9e2c2331-20241214";
exports.version = "19.1.0-native-fb-c80b336d-20241214";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<750b2d06666d3559337bd9db530269cf>>
* @generated SignedSource<<f0bcb042fc8317d7226f720e52e855bc>>
*/

"use strict";
Expand Down Expand Up @@ -203,4 +203,4 @@ exports.useFormState = function (action, initialState, permalink) {
exports.useFormStatus = function () {
return ReactSharedInternals.H.useHostTransitionStatus();
};
exports.version = "19.1.0-native-fb-9e2c2331-20241214";
exports.version = "19.1.0-native-fb-c80b336d-20241214";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<db4ceffbac26f304c1b376b6fa4f7e53>>
* @generated SignedSource<<03e01f84cb39808b8c90a7dbf92877e6>>
*/

/*
Expand Down Expand Up @@ -9373,7 +9373,7 @@ __DEV__ &&
)
return (
isSuspenseInstanceFallback(JSCompiler_object_inline_message_2359)
? (workInProgress.lanes = 16)
? (workInProgress.lanes = 32)
: (workInProgress.lanes = 536870912),
null
);
Expand Down Expand Up @@ -25892,11 +25892,11 @@ __DEV__ &&
};
(function () {
var isomorphicReactPackageVersion = React.version;
if ("19.1.0-native-fb-9e2c2331-20241214" !== isomorphicReactPackageVersion)
if ("19.1.0-native-fb-c80b336d-20241214" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-dom: 19.1.0-native-fb-9e2c2331-20241214\nLearn more: https://react.dev/warnings/version-mismatch")
"\n - react-dom: 19.1.0-native-fb-c80b336d-20241214\nLearn more: https://react.dev/warnings/version-mismatch")
);
})();
("function" === typeof Map &&
Expand Down Expand Up @@ -25933,10 +25933,10 @@ __DEV__ &&
!(function () {
var internals = {
bundleType: 1,
version: "19.1.0-native-fb-9e2c2331-20241214",
version: "19.1.0-native-fb-c80b336d-20241214",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-native-fb-9e2c2331-20241214"
reconcilerVersion: "19.1.0-native-fb-c80b336d-20241214"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -26082,5 +26082,5 @@ __DEV__ &&
listenToAllSupportedEvents(container);
return new ReactDOMHydrationRoot(initialChildren);
};
exports.version = "19.1.0-native-fb-9e2c2331-20241214";
exports.version = "19.1.0-native-fb-c80b336d-20241214";
})();
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<a22926df3838f5b3e46886d7d7143778>>
* @generated SignedSource<<ab5533847781b92efa975129c69ae83a>>
*/

/*
Expand Down Expand Up @@ -6502,7 +6502,7 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
)
return (
isSuspenseInstanceFallback(nextInstance)
? (workInProgress.lanes = 16)
? (workInProgress.lanes = 32)
: (workInProgress.lanes = 536870912),
null
);
Expand Down Expand Up @@ -15868,14 +15868,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
};
var isomorphicReactPackageVersion$jscomp$inline_1722 = React.version;
if (
"19.1.0-native-fb-9e2c2331-20241214" !==
"19.1.0-native-fb-c80b336d-20241214" !==
isomorphicReactPackageVersion$jscomp$inline_1722
)
throw Error(
formatProdErrorMessage(
527,
isomorphicReactPackageVersion$jscomp$inline_1722,
"19.1.0-native-fb-9e2c2331-20241214"
"19.1.0-native-fb-c80b336d-20241214"
)
);
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
Expand All @@ -15897,10 +15897,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
};
var internals$jscomp$inline_2177 = {
bundleType: 0,
version: "19.1.0-native-fb-9e2c2331-20241214",
version: "19.1.0-native-fb-c80b336d-20241214",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-native-fb-9e2c2331-20241214"
reconcilerVersion: "19.1.0-native-fb-c80b336d-20241214"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2178 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -16006,4 +16006,4 @@ exports.hydrateRoot = function (container, initialChildren, options) {
listenToAllSupportedEvents(container);
return new ReactDOMHydrationRoot(initialChildren);
};
exports.version = "19.1.0-native-fb-9e2c2331-20241214";
exports.version = "19.1.0-native-fb-c80b336d-20241214";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<a1a2ffa1e06fe7305ac6adf7b61b782b>>
* @generated SignedSource<<1681109a0889143a0df7d9cf010ae81f>>
*/

/*
Expand Down Expand Up @@ -6673,7 +6673,7 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
)
return (
isSuspenseInstanceFallback(nextInstance)
? (workInProgress.lanes = 16)
? (workInProgress.lanes = 32)
: (workInProgress.lanes = 536870912),
null
);
Expand Down Expand Up @@ -16521,14 +16521,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
};
var isomorphicReactPackageVersion$jscomp$inline_1812 = React.version;
if (
"19.1.0-native-fb-9e2c2331-20241214" !==
"19.1.0-native-fb-c80b336d-20241214" !==
isomorphicReactPackageVersion$jscomp$inline_1812
)
throw Error(
formatProdErrorMessage(
527,
isomorphicReactPackageVersion$jscomp$inline_1812,
"19.1.0-native-fb-9e2c2331-20241214"
"19.1.0-native-fb-c80b336d-20241214"
)
);
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
Expand All @@ -16550,10 +16550,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
};
var internals$jscomp$inline_1819 = {
bundleType: 0,
version: "19.1.0-native-fb-9e2c2331-20241214",
version: "19.1.0-native-fb-c80b336d-20241214",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-native-fb-9e2c2331-20241214",
reconcilerVersion: "19.1.0-native-fb-c80b336d-20241214",
getLaneLabelMap: function () {
for (
var map = new Map(), lane = 1, index$292 = 0;
Expand Down Expand Up @@ -16674,4 +16674,4 @@ exports.hydrateRoot = function (container, initialChildren, options) {
listenToAllSupportedEvents(container);
return new ReactDOMHydrationRoot(initialChildren);
};
exports.version = "19.1.0-native-fb-9e2c2331-20241214";
exports.version = "19.1.0-native-fb-c80b336d-20241214";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<825c11edcd2ee7ed58188f82d885fd25>>
* @generated SignedSource<<719f0629f8481ddd89d7c9288e4aa8b4>>
*/

/*
Expand Down Expand Up @@ -9381,7 +9381,7 @@ __DEV__ &&
)
return (
isSuspenseInstanceFallback(JSCompiler_object_inline_message_2364)
? (workInProgress.lanes = 16)
? (workInProgress.lanes = 32)
: (workInProgress.lanes = 536870912),
null
);
Expand Down Expand Up @@ -25953,11 +25953,11 @@ __DEV__ &&
};
(function () {
var isomorphicReactPackageVersion = React.version;
if ("19.1.0-native-fb-9e2c2331-20241214" !== isomorphicReactPackageVersion)
if ("19.1.0-native-fb-c80b336d-20241214" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-dom: 19.1.0-native-fb-9e2c2331-20241214\nLearn more: https://react.dev/warnings/version-mismatch")
"\n - react-dom: 19.1.0-native-fb-c80b336d-20241214\nLearn more: https://react.dev/warnings/version-mismatch")
);
})();
("function" === typeof Map &&
Expand Down Expand Up @@ -25994,10 +25994,10 @@ __DEV__ &&
!(function () {
var internals = {
bundleType: 1,
version: "19.1.0-native-fb-9e2c2331-20241214",
version: "19.1.0-native-fb-c80b336d-20241214",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-native-fb-9e2c2331-20241214"
reconcilerVersion: "19.1.0-native-fb-c80b336d-20241214"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -26459,7 +26459,7 @@ __DEV__ &&
exports.useFormStatus = function () {
return resolveDispatcher().useHostTransitionStatus();
};
exports.version = "19.1.0-native-fb-9e2c2331-20241214";
exports.version = "19.1.0-native-fb-c80b336d-20241214";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<2aa5c03847a74c5afdf858f203e29b9f>>
* @generated SignedSource<<3b25e566cb2bc3ac9041a366f4c25e6c>>
*/

/*
Expand Down Expand Up @@ -6502,7 +6502,7 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
)
return (
isSuspenseInstanceFallback(nextInstance)
? (workInProgress.lanes = 16)
? (workInProgress.lanes = 32)
: (workInProgress.lanes = 536870912),
null
);
Expand Down Expand Up @@ -15879,14 +15879,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
};
var isomorphicReactPackageVersion$jscomp$inline_1723 = React.version;
if (
"19.1.0-native-fb-9e2c2331-20241214" !==
"19.1.0-native-fb-c80b336d-20241214" !==
isomorphicReactPackageVersion$jscomp$inline_1723
)
throw Error(
formatProdErrorMessage(
527,
isomorphicReactPackageVersion$jscomp$inline_1723,
"19.1.0-native-fb-9e2c2331-20241214"
"19.1.0-native-fb-c80b336d-20241214"
)
);
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
Expand All @@ -15908,10 +15908,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
};
var internals$jscomp$inline_2180 = {
bundleType: 0,
version: "19.1.0-native-fb-9e2c2331-20241214",
version: "19.1.0-native-fb-c80b336d-20241214",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-native-fb-9e2c2331-20241214"
reconcilerVersion: "19.1.0-native-fb-c80b336d-20241214"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2181 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -16171,4 +16171,4 @@ exports.useFormState = function (action, initialState, permalink) {
exports.useFormStatus = function () {
return ReactSharedInternals.H.useHostTransitionStatus();
};
exports.version = "19.1.0-native-fb-9e2c2331-20241214";
exports.version = "19.1.0-native-fb-c80b336d-20241214";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<b27ce938e21df2fb962bb736e9832adf>>
* @generated SignedSource<<1666a1c7d7bc9b1a4a864817ffa0f00f>>
*/

/*
Expand Down Expand Up @@ -6677,7 +6677,7 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
)
return (
isSuspenseInstanceFallback(nextInstance)
? (workInProgress.lanes = 16)
? (workInProgress.lanes = 32)
: (workInProgress.lanes = 536870912),
null
);
Expand Down Expand Up @@ -16536,14 +16536,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
};
var isomorphicReactPackageVersion$jscomp$inline_1813 = React.version;
if (
"19.1.0-native-fb-9e2c2331-20241214" !==
"19.1.0-native-fb-c80b336d-20241214" !==
isomorphicReactPackageVersion$jscomp$inline_1813
)
throw Error(
formatProdErrorMessage(
527,
isomorphicReactPackageVersion$jscomp$inline_1813,
"19.1.0-native-fb-9e2c2331-20241214"
"19.1.0-native-fb-c80b336d-20241214"
)
);
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
Expand All @@ -16565,10 +16565,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
};
var internals$jscomp$inline_1820 = {
bundleType: 0,
version: "19.1.0-native-fb-9e2c2331-20241214",
version: "19.1.0-native-fb-c80b336d-20241214",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-native-fb-9e2c2331-20241214",
reconcilerVersion: "19.1.0-native-fb-c80b336d-20241214",
getLaneLabelMap: function () {
for (
var map = new Map(), lane = 1, index$292 = 0;
Expand Down Expand Up @@ -16843,7 +16843,7 @@ exports.useFormState = function (action, initialState, permalink) {
exports.useFormStatus = function () {
return ReactSharedInternals.H.useHostTransitionStatus();
};
exports.version = "19.1.0-native-fb-9e2c2331-20241214";
exports.version = "19.1.0-native-fb-c80b336d-20241214";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Loading

0 comments on commit cba1fef

Please sign in to comment.