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

Refactor Expiration Time Model #17669

Closed
wants to merge 9 commits into from

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Dec 19, 2019

Based on #17418

Stack of changes to replace our "expiration time" model with something better.

  • Decouple expiration times from transition timeouts

@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 19, 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 0699c38:

Sandbox Source
nostalgic-forest-msuox Configuration

@sizebot
Copy link

sizebot commented Dec 19, 2019

Details of bundled changes.

Comparing: e706721...0699c38

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js +1.5% +1.9% 123.16 KB 125.06 KB 38.74 KB 39.48 KB NODE_PROFILING
react-dom-server.browser.development.js 0.0% 0.0% 137.73 KB 137.73 KB 36.6 KB 36.61 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 20.47 KB 20.47 KB 7.5 KB 7.5 KB UMD_PROD
ReactDOMServer-prod.js 0.0% 0.0% 49.02 KB 49.02 KB 11.19 KB 11.19 KB FB_WWW_PROD
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-test-utils.development.js 0.0% 0.0% 52.77 KB 52.77 KB 14.99 KB 14.99 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.1% 10.95 KB 10.95 KB 4.09 KB 4.09 KB NODE_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.2% 1.05 KB 1.05 KB 643 B 642 B NODE_PROD
react-dom.development.js +1.8% +1.3% 949.91 KB 967.33 KB 214.82 KB 217.6 KB UMD_DEV
react-dom.production.min.js 🔺+1.6% 🔺+1.8% 119.18 KB 121.13 KB 38.29 KB 38.98 KB UMD_PROD
react-dom.profiling.min.js +1.6% +1.7% 122.92 KB 124.87 KB 39.52 KB 40.2 KB UMD_PROFILING
react-dom.development.js +1.8% +1.3% 943.98 KB 961.39 KB 213.1 KB 215.92 KB NODE_DEV
react-dom-server.node.development.js 0.0% 0.0% 134.77 KB 134.77 KB 35.81 KB 35.81 KB NODE_DEV
react-dom.production.min.js 🔺+1.6% 🔺+1.7% 119.28 KB 121.17 KB 37.61 KB 38.24 KB NODE_PROD
ReactTestUtils-dev.js +0.1% +0.1% 52.37 KB 52.44 KB 14.28 KB 14.29 KB FB_WWW_DEV
react-dom-server.browser.development.js 0.0% 0.0% 133.66 KB 133.66 KB 35.58 KB 35.58 KB NODE_DEV
ReactDOM-dev.js +1.8% +1.4% 971.8 KB 989.41 KB 216.06 KB 219 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+1.5% 🔺+1.6% 393.68 KB 399.71 KB 72.09 KB 73.26 KB FB_WWW_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 60.91 KB 60.91 KB 16.07 KB 16.07 KB UMD_DEV
ReactDOM-profiling.js +1.5% +1.6% 404.98 KB 411.02 KB 74.24 KB 75.4 KB FB_WWW_PROFILING
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 60.61 KB 60.61 KB 16 KB 16 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
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 9.97 KB 9.97 KB 3.37 KB 3.38 KB NODE_PROD
ReactDOMServer-dev.js 0.0% 0.0% 139.4 KB 139.47 KB 35.43 KB 35.45 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 +2.8% +2.1% 616.27 KB 633.69 KB 131.31 KB 134.11 KB UMD_DEV
react-test-renderer.production.min.js 🔺+2.7% 🔺+3.3% 71.5 KB 73.44 KB 21.91 KB 22.63 KB UMD_PROD
react-test-renderer-shallow.development.js 0.0% 0.0% 37.83 KB 37.83 KB 9.81 KB 9.81 KB UMD_DEV
react-test-renderer-shallow.production.min.js 0.0% 0.0% 11.66 KB 11.66 KB 3.6 KB 3.6 KB UMD_PROD
react-test-renderer-shallow.development.js 0.0% 0.0% 32.37 KB 32.37 KB 8.5 KB 8.5 KB NODE_DEV
react-test-renderer.development.js +2.8% +2.2% 611.54 KB 628.95 KB 130.13 KB 132.93 KB NODE_DEV
react-test-renderer.production.min.js 🔺+2.7% 🔺+2.9% 71.19 KB 73.08 KB 21.53 KB 22.16 KB NODE_PROD
ReactTestRenderer-dev.js +2.8% +2.2% 627.38 KB 644.96 KB 130.91 KB 133.73 KB FB_WWW_DEV

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +2.4% +1.8% 744.38 KB 761.94 KB 157.73 KB 160.57 KB RN_OSS_DEV
ReactFabric-dev.js +2.4% +1.8% 734.76 KB 752.32 KB 155.43 KB 158.24 KB RN_OSS_DEV
ReactNativeRenderer-dev.js +2.4% +1.8% 744.55 KB 762.11 KB 157.83 KB 160.66 KB RN_FB_DEV
ReactFabric-prod.js 🔺+2.5% 🔺+2.2% 265.75 KB 272.31 KB 45.73 KB 46.75 KB RN_OSS_PROD
ReactNativeRenderer-prod.js 🔺+2.2% 🔺+2.1% 273.79 KB 279.79 KB 47.09 KB 48.05 KB RN_FB_PROD
ReactFabric-profiling.js +2.4% +2.1% 276.87 KB 283.46 KB 47.86 KB 48.88 KB RN_OSS_PROFILING
ReactNativeRenderer-profiling.js +2.1% +2.0% 284.96 KB 290.98 KB 49.23 KB 50.21 KB RN_FB_PROFILING
ReactNativeRenderer-prod.js 🔺+2.4% 🔺+2.3% 273.4 KB 279.97 KB 47.01 KB 48.1 KB RN_OSS_PROD
ReactFabric-dev.js +2.4% +1.8% 734.94 KB 752.5 KB 155.52 KB 158.33 KB RN_FB_DEV
ReactNativeRenderer-profiling.js +2.3% +2.2% 284.58 KB 291.16 KB 49.16 KB 50.25 KB RN_OSS_PROFILING
ReactFabric-prod.js 🔺+2.3% 🔺+1.9% 266.09 KB 272.09 KB 45.81 KB 46.7 KB RN_FB_PROD
ReactFabric-profiling.js +2.2% +1.9% 277.22 KB 283.23 KB 47.92 KB 48.82 KB RN_FB_PROFILING

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactART-dev.js +2.9% +2.2% 615.78 KB 633.39 KB 128.39 KB 131.18 KB FB_WWW_DEV
ReactART-prod.js 🔺+2.9% 🔺+2.9% 236.25 KB 242.98 KB 39.92 KB 41.08 KB FB_WWW_PROD
react-art.development.js +2.6% +1.9% 671.24 KB 688.66 KB 145.69 KB 148.49 KB UMD_DEV
react-art.production.min.js 🔺+1.8% 🔺+2.0% 106.83 KB 108.77 KB 32.5 KB 33.14 KB UMD_PROD
react-art.development.js +2.9% +2.2% 601.92 KB 619.34 KB 128.28 KB 131.07 KB NODE_DEV
react-art.production.min.js 🔺+2.6% 🔺+2.7% 71.78 KB 73.68 KB 21.65 KB 22.23 KB NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler-persistent.development.js +2.9% +2.2% 600.37 KB 617.79 KB 126.34 KB 129.15 KB NODE_DEV
react-reconciler-reflection.development.js 0.0% 0.0% 19.27 KB 19.27 KB 6.33 KB 6.33 KB NODE_DEV
react-reconciler-persistent.production.min.js 🔺+2.6% 🔺+3.0% 72.09 KB 73.99 KB 21.24 KB 21.87 KB NODE_PROD
react-reconciler.development.js +2.9% +2.2% 602.92 KB 620.34 KB 127.45 KB 130.24 KB NODE_DEV
react-reconciler.production.min.js 🔺+2.5% 🔺+3.0% 74.79 KB 76.69 KB 21.91 KB 22.56 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: 0.0%

Size changes (experimental)

Generated by 🚫 dangerJS against 0699c38

@sizebot
Copy link

sizebot commented Dec 19, 2019

Details of bundled changes.

Comparing: e706721...0699c38

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.production.min.js 🔺+1.7% 🔺+1.9% 104.33 KB 106.12 KB 31.8 KB 32.41 KB UMD_PROD
react-art.development.js +2.6% +1.9% 671.22 KB 688.64 KB 145.68 KB 148.49 KB UMD_DEV
react-art.development.js +2.9% +2.2% 601.9 KB 619.31 KB 128.28 KB 131.07 KB NODE_DEV
react-art.production.min.js 🔺+2.5% 🔺+2.7% 69.33 KB 71.07 KB 20.96 KB 21.52 KB NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler-persistent.production.min.js 🔺+2.4% 🔺+2.7% 72.08 KB 73.83 KB 21.24 KB 21.8 KB NODE_PROD
react-reconciler.development.js +2.9% +2.2% 602.91 KB 620.33 KB 127.45 KB 130.24 KB NODE_DEV
react-reconciler.production.min.js 🔺+2.4% 🔺+2.7% 72.06 KB 73.81 KB 21.23 KB 21.8 KB NODE_PROD
react-reconciler-reflection.development.js 0.0% 0.0% 19.25 KB 19.25 KB 6.33 KB 6.33 KB NODE_DEV
react-reconciler-persistent.development.js +2.9% +2.2% 600.36 KB 617.77 KB 126.33 KB 129.14 KB NODE_DEV

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactFabric-dev.js +2.4% +1.8% 734.75 KB 752.3 KB 155.42 KB 158.24 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+2.3% 🔺+2.0% 265.73 KB 271.73 KB 45.73 KB 46.63 KB RN_OSS_PROD
ReactNativeRenderer-dev.js +2.4% +1.8% 744.37 KB 761.92 KB 157.73 KB 160.56 KB RN_OSS_DEV
ReactFabric-profiling.js +2.2% +1.9% 276.86 KB 282.88 KB 47.85 KB 48.75 KB RN_OSS_PROFILING
ReactNativeRenderer-prod.js 🔺+2.2% 🔺+2.1% 273.39 KB 279.39 KB 47.01 KB 47.97 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +2.1% +2.0% 284.56 KB 290.58 KB 49.15 KB 50.13 KB RN_OSS_PROFILING

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom-test-utils.development.js 0.0% 0.0% 52.76 KB 52.76 KB 14.99 KB 14.99 KB NODE_DEV
react-dom.production.min.js 🔺+1.6% 🔺+1.8% 115.35 KB 117.15 KB 37.18 KB 37.84 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 60.59 KB 60.59 KB 15.99 KB 15.99 KB NODE_DEV
react-dom.profiling.min.js +1.5% +1.6% 118.98 KB 120.78 KB 38.37 KB 38.97 KB UMD_PROFILING
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 9.96 KB 9.96 KB 3.37 KB 3.37 KB NODE_PROD
react-dom.development.js +1.8% +1.3% 943.96 KB 961.37 KB 213.08 KB 215.89 KB NODE_DEV
react-dom.production.min.js 🔺+1.5% 🔺+1.5% 115.41 KB 117.15 KB 36.54 KB 37.08 KB NODE_PROD
react-dom.profiling.min.js +1.5% +1.5% 119.18 KB 120.92 KB 37.66 KB 38.21 KB NODE_PROFILING
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-server.browser.development.js 0.0% 0.0% 137.71 KB 137.71 KB 36.6 KB 36.6 KB UMD_DEV
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.7 KB 3.7 KB 1.5 KB 1.5 KB NODE_DEV
react-dom-test-utils.development.js 0.0% 0.0% 54.48 KB 54.48 KB 15.31 KB 15.31 KB UMD_DEV
react-dom-server.browser.development.js 0.0% 0.0% 133.64 KB 133.64 KB 35.58 KB 35.58 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.1% 10.94 KB 10.94 KB 4.08 KB 4.08 KB NODE_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-unstable-native-dependencies.development.js 0.0% 0.0% 60.89 KB 60.89 KB 16.07 KB 16.07 KB UMD_DEV
react-dom-server.node.development.js 0.0% 0.0% 134.75 KB 134.75 KB 35.81 KB 35.81 KB NODE_DEV
react-dom.development.js +1.8% +1.3% 949.89 KB 967.31 KB 214.79 KB 217.57 KB UMD_DEV

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer-shallow.development.js 0.0% 0.0% 37.81 KB 37.81 KB 9.8 KB 9.8 KB UMD_DEV
react-test-renderer-shallow.development.js 0.0% 0.0% 32.35 KB 32.35 KB 8.49 KB 8.49 KB NODE_DEV
react-test-renderer.development.js +2.8% +2.1% 616.25 KB 633.66 KB 131.3 KB 134.1 KB UMD_DEV
react-test-renderer.production.min.js 🔺+2.5% 🔺+3.0% 71.48 KB 73.27 KB 21.89 KB 22.54 KB UMD_PROD
react-test-renderer.development.js +2.8% +2.2% 611.51 KB 628.93 KB 130.12 KB 132.92 KB NODE_DEV
react-test-renderer.production.min.js 🔺+2.4% 🔺+2.6% 71.17 KB 72.91 KB 21.51 KB 22.08 KB NODE_PROD

ReactDOM: size: 🔺+1.6%, gzip: 🔺+1.8%

Size changes (stable)

Generated by 🚫 dangerJS against 0699c38

@necolas necolas added the React Core Team Opened by a member of the React Core Team label Jan 8, 2020
Follow up to facebook#17484, which was reverted due to a bug found in www.
When resetting render phase updates after a throw, we should only clear
the pending queue of hooks that were already processed.
Detects if a queue has been processed by whether the hook was cloned.
If we change the implementation to an array instead of a list, we'll
need some other mechanism to determine whether the hook was processed.
useTransition uses the state hook as part of its implementation, so we
need to fork it in the dispatcher used for re-renders, too.
The `isPending` state managed by the `useTransition` queue can be
modeled using the same queue as useState/useReducer; that's how it's
implemented today. However, since there's only ever a single pending
transition per `useTransition` hook, and the most recent one always
wins, we don't really need to maintain an entire queue structure.

This replaces the internal `useState` queue with a specialized
implementation. It tracks the most recent transition expiration time
on shared instance object, and the last processed expiration time on
each hook copy. When the processed expiration time catches up to the
pending one, we know that the transition is no longer pending. At a
high level, this is also how the `useState` queue works, but without
the overhead of an actual queue.

The implementation is also inspired by Suspense boundaries, which also
have an internal state for whether the boundary is displaying a
fallback, but does not use an actual queue to manage that state.
When multiple transitions update the same queue, only the most recent
one should be considered pending.

Example: If I switch tabs multiple times, only the last tab I click
should display a pending state (e.g. an inline spinner).
When multiple transitions update the same queue, only the most recent
one should be allowed to finish. Do not display intermediate states.

For example, if you click on multiple tabs in quick succession, we
should not switch to any tab that isn't the last one you clicked.
We currently use the expiration time to represent the timeout of a
transition. Since we intend to stop treating work priority as a
timeline, we can no longer use this trick.

In this commit, I've changed it to store the event time on the update
object instead. Long term, we will store event time on the root as a map
of transition -> event time. I'm only storing it on the update object
as a temporary workaround to unblock the rest of the changes.
I'm about to remove the expiration times train model. This commit
fixes tests that are coupled to that model's implementation.

I have intentionally made these changes in their own commit, without
changing any of the implementation, to show that they pass both before
and after.

I disabled some tests that are inherently coupled to expiration times.
Some of them may need to be replaced with an equivalent test once the
new model is in place.
@rickhanlonii
Copy link
Member

Can close this?

@gaearon
Copy link
Collaborator

gaearon commented Apr 3, 2022

Closing as stale.

@gaearon gaearon closed this Apr 3, 2022
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.

6 participants