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

Adjust SuspenseList CPU bound heuristic #17455

Merged
merged 2 commits into from Dec 3, 2019

Conversation

sebmarkbage
Copy link
Collaborator

In SuspenseList we switch to rendering fallbacks (or stop rendering further rows in the case of tail="collapsed/hidden") if it takes more than 500ms to render the list. The limit of 500ms is similar to the train model and designed to be short enough to be in the not noticeable range.

This works well if each row is small because we time the 500ms range well. However, if we have a few large rows then we're likely to exceed the limit by a lot. E.g. two 480ms rows hits almost a second instead of 500ms.

This PR adjusts the heuristic to instead compute whether something has expired based on the render time of the last row. I.e. if we think rendering one more row would exceed the timeout, then we don't attempt.

This still works well for small rows and bails earlier for large rows.

The expiration is still based on the start of the list rather than the start of the render. It should probably be based on the start of the render but that's a bigger change and needs some thought.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 26, 2019

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1c7a133:

Sandbox Source
gracious-wiles-ykdru Configuration

@sizebot
Copy link

sizebot commented Nov 26, 2019

Details of bundled changes.

Comparing: b64938e...1c7a133

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js +0.1% +0.2% 618.58 KB 619.27 KB 131.78 KB 131.99 KB UMD_DEV
react-test-renderer.production.min.js 🔺+0.1% 🔺+0.1% 71.65 KB 71.74 KB 21.95 KB 21.97 KB UMD_PROD
ReactTestRenderer-dev.js +0.1% +0.2% 629.41 KB 630.11 KB 130.98 KB 131.19 KB FB_WWW_DEV
react-test-renderer-shallow.development.js 0.0% -0.0% 39.11 KB 39.11 KB 10.01 KB 10.01 KB UMD_DEV
react-test-renderer-shallow.production.min.js 0.0% -0.1% 11.6 KB 11.6 KB 3.58 KB 3.58 KB UMD_PROD
react-test-renderer-shallow.production.min.js 0.0% -0.0% 11.73 KB 11.73 KB 3.69 KB 3.69 KB NODE_PROD
react-test-renderer.development.js +0.1% +0.2% 613.85 KB 614.54 KB 130.59 KB 130.8 KB NODE_DEV
react-test-renderer.production.min.js 🔺+0.1% 🔺+0.1% 71.35 KB 71.44 KB 21.56 KB 21.59 KB NODE_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactFabric-prod.js 🔺+0.1% 🔺+0.2% 268.98 KB 269.15 KB 46.11 KB 46.19 KB RN_FB_PROD
ReactNativeRenderer-dev.js +0.1% +0.1% 749.68 KB 750.38 KB 158.62 KB 158.83 KB RN_OSS_DEV
ReactFabric-profiling.js +0.1% +0.1% 279.11 KB 279.26 KB 47.99 KB 48.02 KB RN_FB_PROFILING
ReactNativeRenderer-prod.js 🔺+0.1% 🔺+0.1% 277.32 KB 277.5 KB 47.54 KB 47.58 KB RN_FB_PROD
ReactNativeRenderer-profiling.js +0.1% +0.1% 286.28 KB 286.43 KB 49.27 KB 49.29 KB RN_FB_PROFILING
ReactFabric-dev.js +0.1% +0.1% 755.09 KB 755.79 KB 159.44 KB 159.66 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+0.1% 🔺+0.2% 268.63 KB 268.8 KB 46.04 KB 46.11 KB RN_OSS_PROD
ReactFabric-profiling.js +0.1% +0.1% 278.76 KB 278.92 KB 47.92 KB 47.95 KB RN_OSS_PROFILING
ReactFabric-dev.js +0.1% +0.1% 755.28 KB 755.97 KB 159.53 KB 159.74 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+0.1% 🔺+0.1% 276.93 KB 277.11 KB 47.47 KB 47.51 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +0.1% 0.0% 285.89 KB 286.05 KB 49.2 KB 49.22 KB RN_OSS_PROFILING
ReactNativeRenderer-dev.js +0.1% +0.1% 749.86 KB 750.55 KB 158.7 KB 158.92 KB RN_FB_DEV

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js +0.1% +0.1% 123.53 KB 123.62 KB 38.84 KB 38.86 KB NODE_PROFILING
react-dom-server.browser.production.min.js 0.0% -0.0% 20.39 KB 20.39 KB 7.48 KB 7.48 KB UMD_PROD
react-dom-test-utils.development.js 0.0% -0.0% 56.21 KB 56.21 KB 15.55 KB 15.55 KB UMD_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.88 KB 3.88 KB 1.55 KB 1.55 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.1% 1.21 KB 1.21 KB 711 B 710 B UMD_PROD
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.71 KB 3.71 KB 1.5 KB 1.5 KB NODE_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.3% 1.05 KB 1.05 KB 643 B 641 B NODE_PROD
react-dom.development.js +0.1% +0.1% 954.03 KB 954.72 KB 215.61 KB 215.83 KB UMD_DEV
react-dom.production.min.js 🔺+0.1% 🔺+0.2% 119.59 KB 119.68 KB 38.42 KB 38.48 KB UMD_PROD
react-dom.profiling.min.js +0.1% +0.1% 123.27 KB 123.36 KB 39.53 KB 39.56 KB UMD_PROFILING
react-dom.development.js +0.1% +0.1% 948.1 KB 948.79 KB 214.03 KB 214.25 KB NODE_DEV
react-dom-server.node.development.js 0.0% -0.0% 137.5 KB 137.5 KB 36.14 KB 36.14 KB NODE_DEV
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 119.73 KB 119.82 KB 37.79 KB 37.81 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% -0.0% 20.72 KB 20.72 KB 7.61 KB 7.61 KB NODE_PROD
react-dom-server.browser.development.js 0.0% -0.0% 136.39 KB 136.39 KB 35.91 KB 35.91 KB NODE_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 20.31 KB 20.31 KB 7.46 KB 7.46 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.14 KB 60.14 KB 15.8 KB 15.8 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.73 KB 10.73 KB 3.67 KB 3.67 KB UMD_PROD
ReactDOM-dev.js +0.1% +0.1% 976.19 KB 976.89 KB 216.56 KB 216.77 KB FB_WWW_DEV
ReactDOM-prod.js 0.0% 🔺+0.1% 402.83 KB 403.01 KB 73.37 KB 73.41 KB FB_WWW_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 59.82 KB 59.82 KB 15.66 KB 15.66 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% -0.1% 4.42 KB 4.42 KB 1.65 KB 1.65 KB NODE_DEV
ReactDOM-profiling.js 0.0% 0.0% 403.79 KB 403.94 KB 73.89 KB 73.91 KB FB_WWW_PROFILING
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.48 KB 10.48 KB 3.58 KB 3.57 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% -0.1% 1.21 KB 1.21 KB 698 B 697 B NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactART-dev.js +0.1% +0.2% 617.74 KB 618.43 KB 128.39 KB 128.6 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.1% 🔺+0.1% 236.13 KB 236.31 KB 39.79 KB 39.83 KB FB_WWW_PROD
react-art.development.js +0.1% +0.1% 673.67 KB 674.36 KB 146.07 KB 146.28 KB UMD_DEV
react-art.production.min.js 🔺+0.1% 0.0% 106.67 KB 106.76 KB 32.42 KB 32.43 KB UMD_PROD
react-art.development.js +0.1% +0.2% 604.31 KB 605 KB 128.68 KB 128.89 KB NODE_DEV
react-art.production.min.js 🔺+0.1% 🔺+0.1% 71.64 KB 71.73 KB 21.48 KB 21.51 KB NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler-persistent.development.js +0.1% +0.2% 602.8 KB 603.5 KB 126.76 KB 126.98 KB NODE_DEV
react-reconciler-reflection.development.js 0.0% -0.0% 19.09 KB 19.09 KB 6.23 KB 6.23 KB NODE_DEV
react-reconciler-persistent.production.min.js 🔺+0.1% 🔺+0.2% 72.4 KB 72.49 KB 21.35 KB 21.38 KB NODE_PROD
react-reconciler-reflection.production.min.js 0.0% -0.1% 2.86 KB 2.86 KB 1.24 KB 1.24 KB NODE_PROD
react-reconciler.development.js +0.1% +0.2% 605.33 KB 606.02 KB 127.87 KB 128.08 KB NODE_DEV
react-reconciler.production.min.js 🔺+0.1% 🔺+0.1% 74.67 KB 74.76 KB 21.9 KB 21.92 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: -0.0%

Size changes (experimental)

Generated by 🚫 dangerJS against 1c7a133

@sizebot
Copy link

sizebot commented Nov 26, 2019

Details of bundled changes.

Comparing: b64938e...1c7a133

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.production.min.js 🔺+0.1% 🔺+0.2% 72.37 KB 72.46 KB 21.34 KB 21.37 KB NODE_PROD
react-reconciler-reflection.production.min.js 0.0% -0.1% 2.85 KB 2.85 KB 1.24 KB 1.24 KB NODE_PROD
react-reconciler-persistent.development.js +0.1% +0.2% 602.79 KB 603.48 KB 126.76 KB 126.97 KB NODE_DEV
react-reconciler-persistent.production.min.js 🔺+0.1% 🔺+0.2% 72.38 KB 72.47 KB 21.34 KB 21.38 KB NODE_PROD
react-reconciler.development.js +0.1% +0.2% 605.32 KB 606.01 KB 127.87 KB 128.08 KB NODE_DEV
react-reconciler-reflection.development.js 0.0% -0.0% 19.08 KB 19.08 KB 6.23 KB 6.23 KB NODE_DEV

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.46 KB 10.46 KB 3.57 KB 3.57 KB NODE_PROD
react-dom-server.browser.development.js 0.0% -0.0% 136.37 KB 136.37 KB 35.91 KB 35.91 KB NODE_DEV
react-dom.development.js +0.1% +0.1% 954.01 KB 954.7 KB 215.59 KB 215.81 KB UMD_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.87 KB 3.87 KB 1.54 KB 1.54 KB UMD_DEV
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 116.18 KB 116.27 KB 37.45 KB 37.49 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.1% 1.2 KB 1.2 KB 703 B 702 B UMD_PROD
react-dom.profiling.min.js +0.1% 0.0% 119.75 KB 119.84 KB 38.56 KB 38.57 KB UMD_PROFILING
react-dom.development.js +0.1% +0.1% 948.08 KB 948.77 KB 214.01 KB 214.22 KB NODE_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.7 KB 3.7 KB 1.5 KB 1.49 KB NODE_DEV
react-dom.production.min.js 🔺+0.1% 0.0% 116.29 KB 116.38 KB 36.86 KB 36.87 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.13 KB 60.13 KB 15.79 KB 15.79 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.3% 1.04 KB 1.04 KB 635 B 633 B NODE_PROD
react-dom.profiling.min.js +0.1% +0.1% 119.98 KB 120.07 KB 37.87 KB 37.89 KB NODE_PROFILING
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.72 KB 10.72 KB 3.67 KB 3.67 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 59.8 KB 59.8 KB 15.66 KB 15.66 KB NODE_DEV
react-dom-server.node.development.js 0.0% -0.0% 137.48 KB 137.48 KB 36.13 KB 36.13 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 11.17 KB 11.17 KB 4.14 KB 4.14 KB UMD_PROD
react-dom-unstable-fizz.node.development.js 0.0% -0.1% 4.4 KB 4.4 KB 1.64 KB 1.64 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 10.94 KB 10.94 KB 4.08 KB 4.08 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% -0.1% 1.2 KB 1.2 KB 690 B 689 B NODE_PROD
react-dom-server.browser.production.min.js 0.0% -0.0% 19.93 KB 19.93 KB 7.39 KB 7.38 KB UMD_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.1% +0.1% 673.65 KB 674.34 KB 146.07 KB 146.28 KB UMD_DEV
react-art.production.min.js 🔺+0.1% 🔺+0.1% 104.59 KB 104.68 KB 31.83 KB 31.84 KB UMD_PROD
react-art.development.js +0.1% +0.2% 604.28 KB 604.97 KB 128.67 KB 128.88 KB NODE_DEV
react-art.production.min.js 🔺+0.1% 🔺+0.1% 69.61 KB 69.7 KB 21.03 KB 21.05 KB NODE_PROD

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js +0.1% +0.2% 618.55 KB 619.25 KB 131.76 KB 131.98 KB UMD_DEV
react-test-renderer.production.min.js 🔺+0.1% 🔺+0.1% 71.62 KB 71.71 KB 21.93 KB 21.95 KB UMD_PROD
react-test-renderer.development.js +0.1% +0.2% 613.82 KB 614.52 KB 130.57 KB 130.79 KB NODE_DEV
react-test-renderer.production.min.js 🔺+0.1% 🔺+0.1% 71.33 KB 71.42 KB 21.54 KB 21.57 KB NODE_PROD
react-test-renderer-shallow.development.js 0.0% -0.0% 39.1 KB 39.1 KB 10 KB 10 KB UMD_DEV
react-test-renderer-shallow.production.min.js 0.0% -0.0% 11.58 KB 11.58 KB 3.58 KB 3.57 KB UMD_PROD
react-test-renderer-shallow.development.js 0.0% -0.0% 33.05 KB 33.05 KB 8.53 KB 8.53 KB NODE_DEV
react-test-renderer-shallow.production.min.js 0.0% -0.0% 11.72 KB 11.72 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
ReactNativeRenderer-dev.js +0.1% +0.1% 749.84 KB 750.54 KB 158.69 KB 158.91 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+0.1% 🔺+0.1% 277.31 KB 277.48 KB 47.54 KB 47.57 KB RN_FB_PROD
ReactNativeRenderer-profiling.js +0.1% +0.1% 286.26 KB 286.42 KB 49.26 KB 49.29 KB RN_FB_PROFILING
ReactFabric-dev.js +0.1% +0.1% 755.26 KB 755.96 KB 159.52 KB 159.73 KB RN_FB_DEV
ReactFabric-prod.js 🔺+0.1% 🔺+0.2% 268.96 KB 269.14 KB 46.1 KB 46.18 KB RN_FB_PROD
ReactFabric-profiling.js +0.1% +0.1% 279.1 KB 279.25 KB 47.98 KB 48.01 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js +0.1% +0.1% 749.67 KB 750.36 KB 158.61 KB 158.83 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 🔺+0.1% 🔺+0.1% 276.92 KB 277.09 KB 47.46 KB 47.5 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +0.1% 0.0% 285.88 KB 286.03 KB 49.19 KB 49.21 KB RN_OSS_PROFILING
ReactFabric-dev.js +0.1% +0.1% 755.08 KB 755.78 KB 159.44 KB 159.65 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+0.1% 🔺+0.2% 268.62 KB 268.79 KB 46.03 KB 46.1 KB RN_OSS_PROD
ReactFabric-profiling.js +0.1% +0.1% 278.75 KB 278.91 KB 47.91 KB 47.94 KB RN_OSS_PROFILING

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

Size changes (stable)

Generated by 🚫 dangerJS against 1c7a133

Copy link
Collaborator

@acdlite acdlite left a comment

Choose a reason for hiding this comment

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

Test before landing please

@@ -1114,7 +1114,8 @@ function completeWork(
return null;
}
} else if (
now() > renderState.tailExpiration &&
now() * 2 - renderState.renderingStartTime >
Copy link
Collaborator

Choose a reason for hiding this comment

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

Inline comment that translates this into English plz

"The time it took to render last row is greater than time until the expiration"

In SuspenseList we switch to rendering fallbacks (or stop rendering further
rows in the case of tail="collapsed/hidden") if it takes more than 500ms
to render the list. The limit of 500ms is similar to the train model and
designed to be short enough to be in the not noticeable range.

This works well if each row is small because we time the 500ms range well.
However, if we have a few large rows then we're likely to exceed the limit
by a lot. E.g. two 480ms rows hits almost a second instead of 500ms.

This PR adjusts the heuristic to instead compute whether something has
expired based on the render time of the last row. I.e. if we think rendering
one more row would exceed the timeout, then we don't attempt.

This still works well for small rows and bails earlier for large rows.

The expiration is still based on the start of the list rather than the
start of the render. It should probably be based on the start of the render
but that's a bigger change and needs some thought.
@sebmarkbage sebmarkbage merged commit 79572e3 into facebook:master Dec 3, 2019
trueadm pushed a commit to trueadm/react that referenced this pull request Dec 4, 2019
* Adjust SuspenseList CPU bound heuristic

In SuspenseList we switch to rendering fallbacks (or stop rendering further
rows in the case of tail="collapsed/hidden") if it takes more than 500ms
to render the list. The limit of 500ms is similar to the train model and
designed to be short enough to be in the not noticeable range.

This works well if each row is small because we time the 500ms range well.
However, if we have a few large rows then we're likely to exceed the limit
by a lot. E.g. two 480ms rows hits almost a second instead of 500ms.

This PR adjusts the heuristic to instead compute whether something has
expired based on the render time of the last row. I.e. if we think rendering
one more row would exceed the timeout, then we don't attempt.

This still works well for small rows and bails earlier for large rows.

The expiration is still based on the start of the list rather than the
start of the render. It should probably be based on the start of the render
but that's a bigger change and needs some thought.

* Comment
trueadm pushed a commit to trueadm/react that referenced this pull request Dec 4, 2019
* Adjust SuspenseList CPU bound heuristic

In SuspenseList we switch to rendering fallbacks (or stop rendering further
rows in the case of tail="collapsed/hidden") if it takes more than 500ms
to render the list. The limit of 500ms is similar to the train model and
designed to be short enough to be in the not noticeable range.

This works well if each row is small because we time the 500ms range well.
However, if we have a few large rows then we're likely to exceed the limit
by a lot. E.g. two 480ms rows hits almost a second instead of 500ms.

This PR adjusts the heuristic to instead compute whether something has
expired based on the render time of the last row. I.e. if we think rendering
one more row would exceed the timeout, then we don't attempt.

This still works well for small rows and bails earlier for large rows.

The expiration is still based on the start of the list rather than the
start of the render. It should probably be based on the start of the render
but that's a bigger change and needs some thought.

* Comment
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