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

Selective Hydration #16880

Merged
merged 3 commits into from
Sep 25, 2019
Merged

Conversation

sebmarkbage
Copy link
Collaborator

Because hydration in concurrent mode is yieldy, we can switch hydration priority when new events come in. Selective Hydration gives us the ability to increase priority of roots and suspense boundaries based on what is being interacted with.

Discrete events are replayed in order. They are based an intentional user action so they normally have pretty high priority.

Replaying has some quirks given that we don't know if preventDefault will be called or not. Normally we allow the default behavior. However, a lot of times we'll already have received the data necessary to unblock a boundary. I.e. we're CPU bound.

This PR attempts to first synchronously hydrate the path to the discrete target. Only if that fails, do we create a queue to be replayed later.

Currently, hydration of boundaries bump to Normal pri once Suspense thennables resolve which is a bug. However, we probably also want these thennables to schedule work at even higher priority if they're blocking discrete events. I'll do that in a follow up.

@sizebot
Copy link

sizebot commented Sep 25, 2019

ReactDOM: size: 0.0%, gzip: 0.0%

Details of bundled changes.

Comparing: a06d181...46df9f1

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js -0.0% 0.0% 120.79 KB 120.78 KB 38.03 KB 38.03 KB NODE_PROFILING
react-dom-server.browser.development.js 0.0% -0.0% 142.24 KB 142.24 KB 37.14 KB 37.13 KB UMD_DEV
ReactDOM-dev.js +0.2% +0.2% 978.83 KB 980.3 KB 216.14 KB 216.51 KB FB_WWW_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 19.86 KB 19.86 KB 7.37 KB 7.38 KB UMD_PROD
react-dom-test-utils.development.js 0.0% -0.0% 57.53 KB 57.54 KB 15.83 KB 15.83 KB UMD_DEV
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.78 KB 3.78 KB 1.53 KB 1.53 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 11.19 KB 11.19 KB 4.16 KB 4.16 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1.2 KB 1.2 KB 700 B 702 B UMD_PROD
react-dom-test-utils.development.js 0.0% -0.0% 55.81 KB 55.81 KB 15.5 KB 15.5 KB NODE_DEV
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.61 KB 3.61 KB 1.48 KB 1.48 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 10.96 KB 10.96 KB 4.09 KB 4.09 KB NODE_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.2% 1.04 KB 1.04 KB 632 B 633 B NODE_PROD
react-dom.development.js +0.2% +0.2% 953.62 KB 955.06 KB 215.19 KB 215.54 KB UMD_DEV
react-dom.production.min.js -0.0% -0.0% 117.08 KB 117.07 KB 37.71 KB 37.7 KB UMD_PROD
ReactTestUtils-dev.js +0.1% +0.1% 52.49 KB 52.55 KB 14.06 KB 14.08 KB FB_WWW_DEV
react-dom.profiling.min.js -0.0% 0.0% 120.62 KB 120.61 KB 38.72 KB 38.72 KB UMD_PROFILING
react-dom.development.js +0.2% +0.2% 947.67 KB 949.11 KB 213.65 KB 213.99 KB NODE_DEV
react-dom-server.node.development.js 0.0% -0.0% 139.19 KB 139.19 KB 36.36 KB 36.36 KB NODE_DEV
react-dom.production.min.js -0.0% -0.0% 117.1 KB 117.09 KB 36.96 KB 36.95 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% 0.0% 20.2 KB 20.2 KB 7.52 KB 7.52 KB NODE_PROD
ReactDOM-prod.js 🔺+0.2% 🔺+0.2% 391.85 KB 392.69 KB 71.37 KB 71.54 KB FB_WWW_PROD
ReactDOM-profiling.js +0.2% +0.2% 398.16 KB 398.99 KB 72.5 KB 72.67 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% -0.0% 138.17 KB 138.17 KB 36.13 KB 36.13 KB NODE_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 19.79 KB 19.79 KB 7.36 KB 7.36 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 60.73 KB 60.73 KB 15.85 KB 15.85 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.74 KB 10.74 KB 3.67 KB 3.67 KB UMD_PROD
ReactDOMServer-dev.js 0.0% 0.0% 142.09 KB 142.15 KB 35.6 KB 35.62 KB FB_WWW_DEV
ReactDOMServer-prod.js 0.0% 0.0% 48.24 KB 48.24 KB 11.04 KB 11.04 KB FB_WWW_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 60.4 KB 60.4 KB 15.72 KB 15.73 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 3.87 KB 3.87 KB 1.51 KB 1.51 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.49 KB 10.49 KB 3.57 KB 3.57 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.3% 1.1 KB 1.1 KB 666 B 668 B NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.1% +0.1% 601.99 KB 602.44 KB 127.13 KB 127.24 KB NODE_DEV
react-reconciler.production.min.js 🔺+0.2% 🔺+0.3% 71.22 KB 71.4 KB 21.04 KB 21.11 KB NODE_PROD
react-reconciler-reflection.development.js 0.0% -0.0% 20.16 KB 20.17 KB 6.5 KB 6.5 KB NODE_DEV
react-reconciler-reflection.production.min.js 0.0% 🔺+0.1% 2.88 KB 2.88 KB 1.25 KB 1.25 KB NODE_PROD
react-reconciler-persistent.development.js +0.1% +0.1% 599 KB 599.45 KB 125.87 KB 125.97 KB NODE_DEV
react-reconciler-persistent.production.min.js 🔺+0.2% 🔺+0.3% 71.23 KB 71.41 KB 21.05 KB 21.12 KB NODE_PROD

Generated by 🚫 dangerJS against 46df9f1

}
break;
case SuspenseComponent:
flushSync(() => scheduleWork(fiber, Sync));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the methods that automatically flush at the end confusing unless they are at the bottom of the stack. In the work loop I've started to prefer using two separate calls, one to queue the sync work and a second explicit call that flushes it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I also don't like the closure. I would've done it that way but didn't feel justified to move this whole function into WorkLoop. Although the split between WorkLoop and Reconciler is a bit arbitrary right now. Reconciler is effectively just a smaller set of exposed functions from WorkLoop.

let root: FiberRoot = fiber.stateNode;
if (root.hydrate) {
// Flush the first scheduled "update".
flushRoot(root, root.firstPendingTime);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is kind of weird but it makes sense :D

I suppose the other way to model this is, when hydrating, immediately commit the root in a dehydrated state.

@sebmarkbage sebmarkbage merged commit 3694a3b into facebook:master Sep 25, 2019
@gaearon gaearon mentioned this pull request Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants