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

SuspenseList Optimizations #16005

Merged
merged 6 commits into from
Jul 1, 2019

Conversation

sebmarkbage
Copy link
Collaborator

This includes a bunch of refactoring and optimizations to SuspenseList. Individual commits help the review.

The biggest optimization focus on the common case of deep updates inside a fully completed tree.

In the case where nothing in the list was suspended and the children didn't change, we now avoid scanning through the list in the begin phase since we don't need to find a tail.

Additionally, if nothing new suspended in this whole render pass, we can also skip the scan in the complete phase.

@sizebot
Copy link

sizebot commented Jun 27, 2019

ReactDOM: size: 0.0%, gzip: 🔺+0.1%

Details of bundled changes.

Comparing: fbbbea1...ea6d36c

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js +0.6% +0.5% 113.98 KB 114.71 KB 35.99 KB 36.17 KB NODE_PROFILING
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 60.76 KB 60.76 KB 15.84 KB 15.85 KB UMD_DEV
ReactDOM-dev.js +0.5% +0.5% 912.12 KB 916.73 KB 202.37 KB 203.46 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.74 KB 10.74 KB 3.68 KB 3.68 KB UMD_PROD
ReactDOMServer-dev.js 0.0% 0.0% 134.27 KB 134.27 KB 34.44 KB 34.44 KB FB_WWW_DEV
react-dom-unstable-fire.development.js +0.5% +0.5% 889.46 KB 893.94 KB 202.16 KB 203.21 KB UMD_DEV
react-dom-unstable-fire.production.min.js 🔺+0.6% 🔺+0.5% 110.38 KB 111 KB 35.55 KB 35.74 KB UMD_PROD
react-dom-unstable-fire.profiling.min.js +0.6% +0.6% 113.71 KB 114.44 KB 36.57 KB 36.79 KB UMD_PROFILING
react-dom-unstable-fire.development.js +0.5% +0.5% 883.75 KB 888.23 KB 200.65 KB 201.69 KB NODE_DEV
react-dom-unstable-fire.production.min.js 🔺+0.6% 🔺+0.4% 110.46 KB 111.08 KB 35.11 KB 35.26 KB NODE_PROD
react-dom.development.js +0.5% +0.5% 889.12 KB 893.59 KB 202.01 KB 203.06 KB UMD_DEV
react-dom-unstable-fire.profiling.min.js +0.6% +0.5% 113.99 KB 114.72 KB 36 KB 36.17 KB NODE_PROFILING
react-dom-server.browser.development.js 0.0% 0.0% 135.74 KB 135.74 KB 35.81 KB 35.81 KB UMD_DEV
react-dom.production.min.js 🔺+0.6% 🔺+0.5% 110.37 KB 110.98 KB 35.54 KB 35.73 KB UMD_PROD
ReactFire-dev.js +0.5% +0.5% 911.33 KB 915.94 KB 202.25 KB 203.35 KB FB_WWW_DEV
react-dom.profiling.min.js +0.6% +0.6% 113.7 KB 114.42 KB 36.56 KB 36.78 KB UMD_PROFILING
ReactFire-prod.js 🔺+0.8% 🔺+0.5% 357.73 KB 360.47 KB 65.47 KB 65.76 KB FB_WWW_PROD
react-dom.development.js +0.5% +0.5% 883.41 KB 887.88 KB 200.5 KB 201.55 KB NODE_DEV
ReactFire-profiling.js +0.6% +0.4% 364.66 KB 366.79 KB 66.8 KB 67.1 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% -0.0% 131.88 KB 131.88 KB 34.89 KB 34.88 KB NODE_DEV
react-dom.production.min.js 🔺+0.6% 🔺+0.4% 110.45 KB 111.06 KB 35.1 KB 35.25 KB NODE_PROD
ReactDOM-prod.js 🔺+0.7% 🔺+0.5% 369.75 KB 372.49 KB 67.85 KB 68.16 KB FB_WWW_PROD
ReactDOMServer-prod.js 0.0% -0.0% 46.67 KB 46.67 KB 10.74 KB 10.74 KB FB_WWW_PROD
ReactDOM-profiling.js +0.6% +0.4% 376.72 KB 378.85 KB 69.2 KB 69.5 KB FB_WWW_PROFILING
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 60.43 KB 60.43 KB 15.72 KB 15.72 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 3.85 KB 3.85 KB 1.5 KB 1.5 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.48 KB 10.48 KB 3.58 KB 3.58 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.2% 1.1 KB 1.1 KB 664 B 665 B NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.78 KB 3.78 KB 1.52 KB 1.52 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 10.95 KB 10.95 KB 4.01 KB 4.01 KB UMD_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.61 KB 3.61 KB 1.47 KB 1.47 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% 🔺+0.1% 10.71 KB 10.71 KB 3.94 KB 3.95 KB NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactART-dev.js +0.8% +0.9% 564.84 KB 569.45 KB 118.36 KB 119.43 KB FB_WWW_DEV
react-art.development.js +0.7% +0.7% 621.07 KB 625.55 KB 136.26 KB 137.26 KB UMD_DEV
react-art.production.min.js 🔺+0.6% 🔺+0.4% 101.35 KB 101.97 KB 31.05 KB 31.17 KB UMD_PROD
react-art.development.js +0.8% +0.8% 551.93 KB 556.41 KB 118.89 KB 119.89 KB NODE_DEV
react-art.production.min.js 🔺+0.9% 🔺+0.7% 66.4 KB 67.02 KB 20.38 KB 20.53 KB NODE_PROD
ReactART-prod.js 🔺+1.2% 🔺+1.1% 215.14 KB 217.8 KB 36.5 KB 36.91 KB FB_WWW_PROD

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js +0.8% +0.8% 564.14 KB 568.61 KB 121.52 KB 122.53 KB UMD_DEV
react-test-renderer.production.min.js 🔺+0.9% 🔺+0.8% 67.76 KB 68.36 KB 20.83 KB 21 KB UMD_PROD
react-test-renderer.development.js +0.8% +0.8% 559.68 KB 564.15 KB 120.35 KB 121.36 KB NODE_DEV
react-test-renderer.production.min.js 🔺+0.9% 🔺+0.8% 67.47 KB 68.09 KB 20.58 KB 20.74 KB NODE_PROD
ReactTestRenderer-dev.js +0.8% +0.9% 574.61 KB 579.23 KB 120.59 KB 121.7 KB FB_WWW_DEV
react-test-renderer-shallow.development.js 0.0% 0.0% 41.46 KB 41.46 KB 10.78 KB 10.79 KB UMD_DEV
react-test-renderer-shallow.production.min.js 0.0% 0.0% 11.66 KB 11.66 KB 3.56 KB 3.56 KB UMD_PROD
react-test-renderer-shallow.development.js 0.0% 0.0% 35.6 KB 35.6 KB 9.41 KB 9.41 KB NODE_DEV
react-test-renderer-shallow.production.min.js 0.0% 0.0% 11.8 KB 11.8 KB 3.68 KB 3.68 KB NODE_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactFabric-dev.js +0.6% +0.7% 714.41 KB 719.03 KB 151.68 KB 152.77 KB RN_FB_DEV
ReactFabric-prod.js 🔺+1.0% 🔺+0.8% 262.55 KB 265.31 KB 45.35 KB 45.71 KB RN_FB_PROD
ReactNativeRenderer-dev.js +0.7% +0.7% 699.25 KB 703.87 KB 148.91 KB 150 KB RN_OSS_DEV
ReactFabric-profiling.js +0.8% +0.7% 271.18 KB 273.33 KB 46.83 KB 47.17 KB RN_FB_PROFILING
ReactNativeRenderer-prod.js 🔺+1.0% 🔺+0.8% 268.64 KB 271.21 KB 46.21 KB 46.56 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +0.8% +0.8% 276.36 KB 278.64 KB 47.74 KB 48.12 KB RN_OSS_PROFILING
ReactNativeRenderer-dev.js +0.7% +0.7% 699.35 KB 703.96 KB 148.96 KB 150.06 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+1.0% 🔺+0.8% 268.63 KB 271.2 KB 46.22 KB 46.57 KB RN_FB_PROD
ReactNativeRenderer-profiling.js +0.8% +0.8% 276.35 KB 278.63 KB 47.75 KB 48.12 KB RN_FB_PROFILING
ReactFabric-dev.js +0.6% +0.7% 714.31 KB 718.92 KB 151.63 KB 152.73 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+1.0% 🔺+0.8% 262.55 KB 265.3 KB 45.33 KB 45.7 KB RN_OSS_PROD
ReactFabric-profiling.js +0.8% +0.7% 271.18 KB 273.33 KB 46.82 KB 47.16 KB RN_OSS_PROFILING

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler-reflection.development.js 0.0% 0.0% 18.66 KB 18.66 KB 6.03 KB 6.03 KB NODE_DEV
react-reconciler-persistent.development.js +0.8% +0.9% 547.81 KB 552.29 KB 116.36 KB 117.39 KB NODE_DEV
react-reconciler-persistent.production.min.js 🔺+0.9% 🔺+0.7% 67.66 KB 68.27 KB 20.19 KB 20.34 KB NODE_PROD
react-reconciler.development.js +0.8% +0.9% 550.22 KB 554.7 KB 117.42 KB 118.43 KB NODE_DEV
react-reconciler.production.min.js 🔺+0.9% 🔺+0.7% 67.65 KB 68.26 KB 20.19 KB 20.34 KB NODE_PROD

Generated by 🚫 dangerJS

packages/react-reconciler/src/ReactFiberBeginWork.js Outdated Show resolved Hide resolved
// something in the previous committed pass suspended. Otherwise,
// there's no chance so we can skip the expensive call to
// hasSuspendedChildrenAndNewContent.
let cannotBeSuspended =
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like something we could put on the effectTag or a similar bitfield that gets bubbled up during complete/unwind.

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 wanted a tag on each child so that I can use it to efficiently determine the tail in beginWork.

We now are able to bail out of reconciliation and splitting out the tail
during deep updates that hasn't changed the child props. This only
works while the list wasn't suspended before.

I also moved the second render of the "head" to the complete phase. This
cleans it up a bit for the tail collapsing PR.

For this second pass I also use a new technique of resetting the child
Fibers for the second pass. This is effectively a fast path to avoid
reconciling the children against props again.
The effectTag now tracks whether the previous commit was suspended.

This frees up SuspenseListState to be render-phase only state.

We use null to mean the default "independent" mode.
…spended

This optimized the deep update case or initial render without anything
suspending.

We have some information available to us that tell us if nothing has
suspended in the past and nothing has suspended this render pass.

This also fixes a bug where we didn't tag the previous render as having
suspended boundaries if we didn't need to force a rerender.
@sebmarkbage sebmarkbage merged commit 933c664 into facebook:master Jul 1, 2019
trueadm pushed a commit to trueadm/react that referenced this pull request Jul 3, 2019
* Add a bunch of optimizations to SuspenseList

We now are able to bail out of reconciliation and splitting out the tail
during deep updates that hasn't changed the child props. This only
works while the list wasn't suspended before.

I also moved the second render of the "head" to the complete phase. This
cleans it up a bit for the tail collapsing PR.

For this second pass I also use a new technique of resetting the child
Fibers for the second pass. This is effectively a fast path to avoid
reconciling the children against props again.

* Move to didSuspend from SuspenseListState to the effectTag

The effectTag now tracks whether the previous commit was suspended.

This frees up SuspenseListState to be render-phase only state.

We use null to mean the default "independent" mode.

* Rename to SuspenseListState to SuspenseListRenderState

* Reuse SuspenseListRenderState across render passes

* Add optimization to bail out of scanning children if they can't be suspended

This optimized the deep update case or initial render without anything
suspending.

We have some information available to us that tell us if nothing has
suspended in the past and nothing has suspended this render pass.

This also fixes a bug where we didn't tag the previous render as having
suspended boundaries if we didn't need to force a rerender.

* rm printChildren

oops
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.

None yet

4 participants