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

Get next expiration time from FiberRoot #16678

Closed
wants to merge 2 commits into from

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Sep 6, 2019

Based on #16663

Given a FiberRoot, we should be able to determine the next expiration time that needs to be worked on, taking into account the levels that are pending, suspended, pinged, and so on.

This removes the expirationTime argument from scheduleCallbackForRoot, and renames it to ensureRootIsScheduled to reflect the new signature. The expiration time is instead read from the root using a new function, getNextExpirationTimeToWorkOn.

The next step will be to remove the expirationTime argument from renderRoot, too.

A FiberRoot can have pending work at many distinct priorities. (Note: we
refer to these levels as "expiration times" to distinguish the concept
from Scheduler's notion of priority levels, which represent broad
categories of work. React expiration times are more granualar. They're
more like a concurrent thread ID, which also happens to correspond to a
moment on a timeline. It's an overloaded concept and I'm handwaving over
some of the details.)

Given a root, there's no convenient way to read all the pending levels
in the entire tree, i.e. there's no single queue-like structure that
tracks all the levels, because that granularity of information is not
needed by our algorithms. Instead we track the subset of information
that we actually need — most importantly, the highest priority level
that exists in the entire tree.

Aside from that, the other information we track includes the range of
pending levels that are known to be suspended, and therefore should not
be worked on.

This is a refactor of how that information is tracked, and what each
field represents:

- A *pending* level is work that is unfinished, or not yet committed.
  This includes work that is suspended from committing.
  `firstPendingTime` and `lastPendingTime` represent the range of
  pending work. (Previously, "pending" was the same as "not suspended.")
- A *suspended* level is work that did not complete because data was
  missing. `firstSuspendedTime` and `lastSuspendedTime` represent the
  range of suspended work. It is a subset of the pending range. (These
  fields are new to this commit.)
- `nextAfterSuspendedTime` represents the next known level that comes
  after the suspended range.

This commit doesn't change much in terms of observable behavior. The one
change is that, when a level is suspended, React will continue working
on the next known level instead of jumping straight to the last pending
level. Subsequent commits will use this new structure for a more
substantial refactor for how tasks are scheduled per root.
Given a FiberRoot, we should be able to determine the next expiration
time that needs to be worked on, taking into account the levels that
are pending, suspended, pinged, and so on.

This removes the `expirationTime` argument from
`scheduleCallbackForRoot`, and renames it to `ensureRootIsScheduled` to
reflect the new signature. The expiration time is instead read from the
root using a new function, `getNextExpirationTimeToWorkOn`.

The next step will be to remove the `expirationTime` argument from
`renderRoot`, too.
@acdlite acdlite requested a review from sebmarkbage September 6, 2019 03:19
@acdlite acdlite changed the title Get root expiration Get next expiration time from FiberRoot Sep 6, 2019
@sizebot
Copy link

sizebot commented Sep 6, 2019

ReactDOM: size: 0.0%, gzip: 0.0%

Details of bundled changes.

Comparing: 9ce8711...6ace553

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js +0.9% +0.7% 115.32 KB 116.35 KB 36.35 KB 36.59 KB NODE_PROFILING
react-dom-server.browser.development.js 0.0% 0.0% 142.1 KB 142.1 KB 37.12 KB 37.12 KB UMD_DEV
ReactDOM-dev.js +0.4% +0.4% 939.12 KB 943.25 KB 207.42 KB 208.24 KB FB_WWW_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 19.8 KB 19.8 KB 7.36 KB 7.36 KB UMD_PROD
react-dom-test-utils.development.js 0.0% -0.0% 57.25 KB 57.25 KB 15.78 KB 15.78 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 11.18 KB 11.18 KB 4.15 KB 4.15 KB UMD_PROD
react-dom-test-utils.development.js 0.0% -0.0% 55.52 KB 55.52 KB 15.45 KB 15.45 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.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.04 KB 1.04 KB 632 B 633 B NODE_PROD
react-dom.development.js +0.4% +0.4% 914.99 KB 919.05 KB 207.39 KB 208.23 KB UMD_DEV
react-dom.production.min.js 🔺+0.8% 🔺+0.5% 111.71 KB 112.64 KB 36.02 KB 36.21 KB UMD_PROD
react-dom.profiling.min.js +0.9% +0.6% 115.12 KB 116.18 KB 37.08 KB 37.29 KB UMD_PROFILING
react-dom.development.js +0.4% +0.4% 909.08 KB 913.14 KB 205.71 KB 206.55 KB NODE_DEV
react-dom-server.node.development.js 0.0% 0.0% 139.05 KB 139.05 KB 36.34 KB 36.34 KB NODE_DEV
react-dom.production.min.js 🔺+0.8% 🔺+0.5% 111.68 KB 112.6 KB 35.39 KB 35.57 KB NODE_PROD
ReactDOM-prod.js 🔺+0.7% 🔺+0.5% 372 KB 374.53 KB 68.15 KB 68.51 KB FB_WWW_PROD
ReactDOM-profiling.js +0.8% +0.6% 377.55 KB 380.61 KB 69.21 KB 69.63 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% 0.0% 138.04 KB 138.04 KB 36.11 KB 36.11 KB NODE_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 19.73 KB 19.73 KB 7.34 KB 7.34 KB NODE_PROD
ReactDOMServer-prod.js 0.0% -0.0% 48.58 KB 48.58 KB 11.11 KB 11.11 KB FB_WWW_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.39 KB 60.39 KB 15.72 KB 15.72 KB NODE_DEV

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.6% +0.6% 657.27 KB 661.33 KB 143.12 KB 143.91 KB UMD_DEV
react-art.production.min.js 🔺+0.9% 🔺+0.6% 101.93 KB 102.86 KB 31.17 KB 31.37 KB UMD_PROD
react-art.development.js +0.7% +0.6% 587.95 KB 592.01 KB 125.67 KB 126.46 KB NODE_DEV
react-art.production.min.js 🔺+1.4% 🔺+0.9% 66.94 KB 67.87 KB 20.4 KB 20.58 KB NODE_PROD
ReactART-dev.js +0.7% +0.6% 603.18 KB 607.31 KB 125.4 KB 126.19 KB FB_WWW_DEV
ReactART-prod.js 🔺+1.2% 🔺+1.0% 225.92 KB 228.54 KB 38.47 KB 38.84 KB FB_WWW_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-prod.js 🔺+0.9% 🔺+0.7% 269.9 KB 272.25 KB 46.26 KB 46.6 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +1.0% +0.9% 278.4 KB 281.22 KB 47.8 KB 48.26 KB RN_OSS_PROFILING
ReactFabric-prod.js 🔺+0.9% 🔺+0.7% 261.69 KB 264.05 KB 44.95 KB 45.28 KB RN_OSS_PROD
ReactFabric-profiling.js +1.0% +1.0% 270.44 KB 273.25 KB 46.47 KB 46.93 KB RN_OSS_PROFILING
ReactFabric-dev.js +0.6% +0.5% 742.49 KB 746.62 KB 156.9 KB 157.73 KB RN_FB_DEV
ReactFabric-prod.js 🔺+0.9% 🔺+0.7% 261.7 KB 264.05 KB 44.96 KB 45.29 KB RN_FB_PROD
ReactNativeRenderer-dev.js +0.6% +0.5% 735.89 KB 740.02 KB 155.72 KB 156.55 KB RN_OSS_DEV
ReactFabric-profiling.js +1.0% +1.0% 270.44 KB 273.25 KB 46.48 KB 46.94 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js +0.6% +0.5% 736.05 KB 740.18 KB 155.81 KB 156.64 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+0.9% 🔺+0.7% 269.9 KB 272.25 KB 46.27 KB 46.61 KB RN_FB_PROD
ReactNativeRenderer-profiling.js +1.0% +0.9% 278.39 KB 281.21 KB 47.81 KB 48.26 KB RN_FB_PROFILING
ReactFabric-dev.js +0.6% +0.5% 742.32 KB 746.45 KB 156.83 KB 157.66 KB RN_OSS_DEV

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactTestRenderer-dev.js +0.7% +0.6% 614.27 KB 618.4 KB 127.81 KB 128.59 KB FB_WWW_DEV
react-test-renderer-shallow.development.js 0.0% -0.0% 39.21 KB 39.21 KB 9.95 KB 9.95 KB UMD_DEV
react-test-renderer-shallow.production.min.js 0.0% 🔺+0.1% 11.41 KB 11.41 KB 3.53 KB 3.53 KB UMD_PROD
react-test-renderer-shallow.development.js 0.0% -0.0% 33.18 KB 33.18 KB 8.49 KB 8.49 KB NODE_DEV
react-test-renderer-shallow.production.min.js 0.0% 🔺+0.1% 11.55 KB 11.55 KB 3.62 KB 3.62 KB NODE_PROD
react-test-renderer.development.js +0.7% +0.6% 601.29 KB 605.35 KB 128.44 KB 129.24 KB UMD_DEV
react-test-renderer.production.min.js 🔺+1.3% 🔺+0.9% 68.88 KB 69.81 KB 21.18 KB 21.38 KB UMD_PROD
react-test-renderer.development.js +0.7% +0.6% 596.63 KB 600.69 KB 127.24 KB 128.04 KB NODE_DEV
react-test-renderer.production.min.js 🔺+1.4% 🔺+0.8% 68.57 KB 69.5 KB 20.9 KB 21.07 KB NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.7% +0.7% 586.59 KB 590.65 KB 124.37 KB 125.2 KB NODE_DEV
react-reconciler.production.min.js 🔺+1.3% 🔺+0.9% 68.94 KB 69.87 KB 20.44 KB 20.63 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-reflection.production.min.js 0.0% -0.1% 2.56 KB 2.56 KB 1.14 KB 1.14 KB NODE_PROD
react-reconciler-persistent.development.js +0.7% +0.7% 583.6 KB 587.66 KB 123.1 KB 123.93 KB NODE_DEV
react-reconciler-persistent.production.min.js 🔺+1.3% 🔺+0.9% 68.95 KB 69.88 KB 20.45 KB 20.64 KB NODE_PROD

Generated by 🚫 dangerJS against 6ace553

// There's a pending update that falls outside the range of
// suspended work.
if (firstPendingTime > expirationTime) {
return renderRoot.bind(null, 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.

As mentioned in #16663. This needs a replacement (and a test).

@acdlite
Copy link
Collaborator Author

acdlite commented Sep 11, 2019

Closed by ab4951f

@acdlite acdlite closed this Sep 11, 2019
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