Skip to content

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Jul 27, 2020

Tasks with SyncBatchedPriority — used by Blocking Mode — should always be rendered by the performSyncWorkOnRoot path, not performConcurrentWorkOnRoot.

Currently, they go through the performConcurrentWorkOnRoot callback. Then, we check didTimeout to see if the task expired. Since SyncBatchedPriority translates to ImmediatePriority in the Scheduler, didTimeout is always true, so we mark it as expired. Then it exits and re-enters in the performSyncWorkOnRoot path.

Aside from being overly convoluted, we shouldn't rely on Scheduler to tell us that SyncBatchedPriority work is synchronous. We should handle that ourselves.

This will allow us to remove the didTimeout check. And it further decouples us from the Scheduler priority, so we can eventually remove that, too.

Tasks with SyncBatchedPriority — used by Blocking Mode — should always
be rendered by the `peformSyncWorkOnRoot` path, not
`performConcurrentWorkOnRoot`.

Currently, they go through the `performConcurrentWorkOnRoot` callback.
Then, we check `didTimeout` to see if the task expired. Since
SyncBatchedPriority translates to ImmediatePriority in the Scheduler,
`didTimeout` is always `true`, so we mark it as expired. Then it exits
and re-enters in the `performSyncWorkOnRoot` path.

Aside from being overly convoluted, we shouldn't rely on Scheduler to
tell us that SyncBatchedPriority work is synchronous. We should handle
that ourselves.

This will allow us to remove the `didTimeout` check. And it further
decouples us from the Scheduler priority, so we can eventually remove
that, too.
@acdlite acdlite requested a review from rickhanlonii July 27, 2020 19:44
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Jul 27, 2020
@acdlite acdlite force-pushed the syncbatched-is-sync branch from 6570dea to 1fb18e2 Compare July 27, 2020 19:47
@codesandbox-ci
Copy link

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 1fb18e2:

Sandbox Source
React Configuration

@sizebot
Copy link

sizebot commented Jul 27, 2020

Details of bundled changes.

Comparing: 96ac799...1fb18e2

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.1% +0.1% 923.37 KB 924.15 KB 209.85 KB 210.04 KB NODE_DEV
ReactDOMForked-prod.js 🔺+0.1% 🔺+0.1% 397.06 KB 397.32 KB 73.74 KB 73.79 KB FB_WWW_PROD
react-dom-server.node.development.js 0.0% -0.0% 138.84 KB 138.84 KB 36.7 KB 36.7 KB NODE_DEV
react-dom.production.min.js 🔺+0.1% 0.0% 124.17 KB 124.24 KB 39.82 KB 39.83 KB NODE_PROD
ReactDOMForked-profiling.js +0.1% +0.1% 412.07 KB 412.33 KB 76.39 KB 76.43 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% -0.0% 145.03 KB 145.03 KB 36.89 KB 36.89 KB UMD_DEV
react-dom-server.node.production.min.js 0.0% -0.0% 20.72 KB 20.72 KB 7.68 KB 7.67 KB NODE_PROD
ReactDOMTesting-dev.js +0.1% +0.1% 958.72 KB 959.52 KB 214.92 KB 215.11 KB FB_WWW_DEV
ReactDOMTesting-prod.js 🔺+0.1% 🔺+0.1% 402.98 KB 403.24 KB 75.83 KB 75.91 KB FB_WWW_PROD
react-dom-test-utils.production.min.js 0.0% 0.0% 12.71 KB 12.71 KB 4.97 KB 4.97 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 5.36 KB 5.36 KB 1.8 KB 1.8 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% -0.2% 1.17 KB 1.17 KB 666 B 665 B NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 4.87 KB 4.87 KB 1.7 KB 1.7 KB NODE_DEV
react-dom.development.js +0.1% +0.1% 969.91 KB 970.72 KB 212.41 KB 212.59 KB UMD_DEV
react-dom.production.min.js 🔺+0.1% 0.0% 124.02 KB 124.1 KB 40.56 KB 40.58 KB UMD_PROD
react-dom.profiling.min.js +0.1% 0.0% 129.2 KB 129.27 KB 42.19 KB 42.2 KB UMD_PROFILING
ReactDOMForked-dev.js +0.1% +0.1% 996.92 KB 997.71 KB 221.97 KB 222.16 KB FB_WWW_DEV
react-dom.profiling.min.js +0.1% 0.0% 129.55 KB 129.62 KB 41.46 KB 41.46 KB NODE_PROFILING
ReactDOM-dev.js +0.1% +0.1% 993.58 KB 994.37 KB 221.71 KB 221.9 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.1% 🔺+0.1% 395.6 KB 395.86 KB 73.46 KB 73.5 KB FB_WWW_PROD
ReactDOM-profiling.js +0.1% +0.1% 409.99 KB 410.26 KB 76.08 KB 76.13 KB FB_WWW_PROFILING
react-dom-server.browser.production.min.js 0.0% -0.0% 20.3 KB 20.3 KB 7.52 KB 7.52 KB NODE_PROD
ReactDOMServer-prod.js 0.0% -0.0% 46.68 KB 46.68 KB 10.93 KB 10.92 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% -0.0% 65.91 KB 65.91 KB 18.18 KB 18.18 KB UMD_DEV

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.1% +0.1% 655.09 KB 655.87 KB 139.5 KB 139.68 KB NODE_DEV
react-reconciler-reflection.development.js 0.0% 0.0% 16.71 KB 16.71 KB 4.98 KB 4.98 KB NODE_DEV
react-reconciler.production.min.js 🔺+0.1% 0.0% 87.69 KB 87.76 KB 26.88 KB 26.89 KB NODE_PROD
react-reconciler-reflection.production.min.js 0.0% -0.1% 2.81 KB 2.81 KB 1.16 KB 1.16 KB NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactART-prod.js 🔺+0.1% 🔺+0.1% 240.24 KB 240.51 KB 42.52 KB 42.57 KB FB_WWW_PROD
react-art.development.js +0.1% +0.1% 694.43 KB 695.24 KB 147.01 KB 147.19 KB UMD_DEV
react-art.production.min.js 🔺+0.1% 🔺+0.1% 112.7 KB 112.77 KB 34.84 KB 34.87 KB UMD_PROD
react-art.development.js +0.1% +0.1% 595.48 KB 596.26 KB 129.16 KB 129.34 KB NODE_DEV
react-art.production.min.js 🔺+0.1% 🔺+0.1% 77.6 KB 77.67 KB 23.98 KB 24 KB NODE_PROD
ReactART-dev.js +0.1% +0.1% 627.52 KB 628.32 KB 133.33 KB 133.52 KB FB_WWW_DEV

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.1% 605.73 KB 606.53 KB 127.31 KB 127.5 KB UMD_DEV
react-test-renderer.production.min.js 🔺+0.1% 🔺+0.1% 76.88 KB 76.95 KB 24.02 KB 24.06 KB UMD_PROD
react-test-renderer.development.js +0.1% +0.1% 577.08 KB 577.86 KB 125.86 KB 126.05 KB NODE_DEV
react-test-renderer.production.min.js 🔺+0.1% 🔺+0.1% 76.69 KB 76.77 KB 23.74 KB 23.77 KB NODE_PROD
ReactTestRenderer-dev.js +0.1% +0.1% 599.98 KB 600.77 KB 128.61 KB 128.79 KB FB_WWW_DEV
ReactTestRenderer-dev.js +0.1% +0.1% 593.33 KB 594.12 KB 128.42 KB 128.61 KB RN_FB_DEV
ReactTestRenderer-prod.js 🔺+0.1% 🔺+0.1% 233.17 KB 233.43 KB 42.55 KB 42.6 KB RN_FB_PROD
ReactTestRenderer-profiling.js +0.1% +0.1% 244.58 KB 244.85 KB 44.68 KB 44.73 KB RN_FB_PROFILING

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +0.1% +0.1% 680.03 KB 680.83 KB 147.45 KB 147.64 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 🔺+0.1% 🔺+0.1% 271.92 KB 272.19 KB 48.37 KB 48.44 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +0.1% +0.1% 283.46 KB 283.72 KB 50.55 KB 50.61 KB RN_OSS_PROFILING
ReactFabric-dev.js +0.1% +0.1% 660.75 KB 661.54 KB 142.78 KB 142.97 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+0.1% 🔺+0.1% 265.75 KB 266.02 KB 47.11 KB 47.17 KB RN_OSS_PROD
ReactFabric-profiling.js +0.1% +0.1% 277.12 KB 277.39 KB 49.3 KB 49.35 KB RN_OSS_PROFILING

Size changes (experimental)

Generated by 🚫 dangerJS against 1fb18e2

@sizebot
Copy link

sizebot commented Jul 27, 2020

Details of bundled changes.

Comparing: 96ac799...1fb18e2

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.1% +0.1% 886.26 KB 887.04 KB 203.04 KB 203.24 KB NODE_DEV
ReactDOMForked-prod.js 🔺+0.1% 🔺+0.1% 408.19 KB 408.45 KB 75.39 KB 75.44 KB FB_WWW_PROD
react-dom-server.node.development.js 0.0% 0.0% 137.33 KB 137.33 KB 36.48 KB 36.49 KB NODE_DEV
react-dom.production.min.js 🔺+0.1% 0.0% 119.37 KB 119.45 KB 38.38 KB 38.39 KB NODE_PROD
ReactDOMForked-profiling.js +0.1% +0.1% 423.26 KB 423.53 KB 78.02 KB 78.07 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% 0.0% 143.44 KB 143.44 KB 36.7 KB 36.7 KB UMD_DEV
react-dom-server.node.production.min.js 0.0% 0.0% 20.26 KB 20.26 KB 7.6 KB 7.6 KB NODE_PROD
ReactDOMTesting-dev.js +0.1% +0.1% 986.88 KB 987.68 KB 220.33 KB 220.52 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% 0.0% 60.88 KB 60.88 KB 17.65 KB 17.65 KB NODE_DEV
ReactDOMTesting-prod.js 🔺+0.1% 🔺+0.1% 415.22 KB 415.49 KB 77.69 KB 77.74 KB FB_WWW_PROD
react-dom-test-utils.production.min.js 0.0% 0.0% 12.7 KB 12.7 KB 4.96 KB 4.96 KB NODE_PROD
react-dom.development.js +0.1% +0.1% 931 KB 931.81 KB 205.53 KB 205.73 KB UMD_DEV
react-dom.production.min.js 🔺+0.1% 0.0% 119.27 KB 119.35 KB 39.06 KB 39.07 KB UMD_PROD
react-dom.profiling.min.js +0.1% +0.1% 123.18 KB 123.25 KB 40.25 KB 40.28 KB UMD_PROFILING
ReactDOMForked-dev.js +0.1% +0.1% 1022.46 KB 1023.25 KB 226.67 KB 226.86 KB FB_WWW_DEV
react-dom.profiling.min.js +0.1% 0.0% 123.44 KB 123.51 KB 39.65 KB 39.67 KB NODE_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 19.92 KB 19.92 KB 7.46 KB 7.46 KB UMD_PROD
ReactDOM-dev.js +0.1% +0.1% 1019.12 KB 1019.91 KB 226.36 KB 226.55 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.1% 🔺+0.1% 406.73 KB 406.99 KB 75.08 KB 75.13 KB FB_WWW_PROD
react-dom-server.browser.development.js 0.0% 0.0% 136.06 KB 136.06 KB 36.24 KB 36.24 KB NODE_DEV
ReactDOM-profiling.js +0.1% +0.1% 421.19 KB 421.45 KB 77.7 KB 77.75 KB FB_WWW_PROFILING
ReactDOMServer-dev.js 0.0% 0.0% 147.44 KB 147.44 KB 37.44 KB 37.44 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% -0.0% 65.9 KB 65.9 KB 18.18 KB 18.17 KB UMD_DEV

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +0.1% +0.1% 685.41 KB 686.21 KB 148.29 KB 148.48 KB RN_FB_DEV
ReactFabric-dev.js +0.1% +0.1% 666.13 KB 666.93 KB 143.63 KB 143.82 KB RN_FB_DEV
ReactNativeRenderer-dev.js +0.1% +0.1% 680.02 KB 680.82 KB 147.44 KB 147.64 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+0.1% 🔺+0.1% 265.71 KB 265.97 KB 47.09 KB 47.15 KB RN_FB_PROD
ReactNativeRenderer-prod.js 🔺+0.1% 🔺+0.1% 271.91 KB 272.17 KB 48.36 KB 48.43 KB RN_OSS_PROD
ReactFabric-profiling.js +0.1% +0.1% 277.07 KB 277.33 KB 49.27 KB 49.32 KB RN_FB_PROFILING
ReactNativeRenderer-profiling.js +0.1% +0.1% 283.44 KB 283.71 KB 50.54 KB 50.6 KB RN_OSS_PROFILING
ReactNativeRenderer-prod.js 🔺+0.1% 🔺+0.1% 271.87 KB 272.13 KB 48.35 KB 48.41 KB RN_FB_PROD
ReactNativeRenderer-profiling.js +0.1% +0.1% 283.39 KB 283.66 KB 50.53 KB 50.58 KB RN_FB_PROFILING
ReactFabric-dev.js +0.1% +0.1% 660.73 KB 661.53 KB 142.77 KB 142.97 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+0.1% 🔺+0.1% 265.74 KB 266.01 KB 47.1 KB 47.16 KB RN_OSS_PROD
ReactFabric-profiling.js +0.1% +0.1% 277.11 KB 277.37 KB 49.29 KB 49.34 KB RN_OSS_PROFILING

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.1% +0.1% 626.74 KB 627.52 KB 134.09 KB 134.27 KB NODE_DEV
react-reconciler.production.min.js 🔺+0.1% 🔺+0.1% 84.34 KB 84.41 KB 25.94 KB 25.96 KB NODE_PROD
react-reconciler-reflection.production.min.js 0.0% -0.1% 2.8 KB 2.8 KB 1.15 KB 1.15 KB NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactART-prod.js 🔺+0.1% 🔺+0.1% 247.39 KB 247.65 KB 43.8 KB 43.85 KB FB_WWW_PROD
react-art.development.js +0.1% +0.1% 667.17 KB 667.98 KB 142 KB 142.18 KB UMD_DEV
react-art.production.min.js 🔺+0.1% 0.0% 109.72 KB 109.8 KB 33.97 KB 33.98 KB UMD_PROD
react-art.development.js +0.1% +0.2% 569.5 KB 570.28 KB 124.23 KB 124.42 KB NODE_DEV
react-art.production.min.js 🔺+0.1% 🔺+0.1% 74.69 KB 74.76 KB 23.11 KB 23.14 KB NODE_PROD
ReactART-dev.js +0.1% +0.1% 637.54 KB 638.33 KB 135.36 KB 135.55 KB FB_WWW_DEV

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.1% 605.7 KB 606.51 KB 127.3 KB 127.49 KB UMD_DEV
react-test-renderer.production.min.js 🔺+0.1% 🔺+0.1% 76.85 KB 76.92 KB 24.01 KB 24.04 KB UMD_PROD
react-test-renderer.development.js +0.1% +0.1% 577.05 KB 577.83 KB 125.85 KB 126.04 KB NODE_DEV
react-test-renderer.production.min.js 🔺+0.1% 🔺+0.1% 76.67 KB 76.74 KB 23.73 KB 23.75 KB NODE_PROD
ReactTestRenderer-dev.js +0.1% +0.1% 599.96 KB 600.76 KB 128.6 KB 128.79 KB FB_WWW_DEV
ReactTestRenderer-dev.js +0.1% +0.1% 593.31 KB 594.11 KB 128.42 KB 128.61 KB RN_FB_DEV
ReactTestRenderer-prod.js 🔺+0.1% 🔺+0.1% 233.16 KB 233.42 KB 42.54 KB 42.59 KB RN_FB_PROD
ReactTestRenderer-profiling.js +0.1% +0.1% 244.57 KB 244.83 KB 44.68 KB 44.72 KB RN_FB_PROFILING

Size changes (stable)

Generated by 🚫 dangerJS against 1fb18e2

Copy link
Member

@rickhanlonii rickhanlonii left a comment

Choose a reason for hiding this comment

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

LGMT

performSyncWorkOnRoot.bind(null, root),
);
} else if (newCallbackPriority === SyncBatchedLanePriority) {
newCallbackNode = scheduleCallback(
Copy link
Member

Choose a reason for hiding this comment

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

Are we intentionally not using scheduleSyncCallback like in the block above?

What if other sync work is already scheduled, do we want this to always come after?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The naming is confusing. scheduleSyncCallback adds stuff to a special queue that can be flushed synchronously without going through Scheduler. It's used for SyncLane and expired updates.

"sync" in performSyncWorkOnRoot means that it doesn't yield to the main thread and it doesn't check Suspense timeouts (though that part might change), so it has fewer checks than concurrent updates.

SyncBatched is kind of a mix between sync mode and concurrent mode. It doesn't yield to the main thread, but it does go through Scheduler (i.e. is scheduled by postMessage), hence the weird naming conflicts.

Copy link
Member

Choose a reason for hiding this comment

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

I see, thanks for explaining 👍

@acdlite acdlite merged commit 722bc04 into facebook:master Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants