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

Track "pending" and "suspended" ranges #16663

Closed
wants to merge 1 commit into from

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Sep 5, 2019

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

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.
@sizebot
Copy link

sizebot commented Sep 5, 2019

ReactDOM: size: 0.0%, gzip: 0.0%

Details of bundled changes.

Comparing: 9ce8711...100945b

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js +0.7% +0.5% 115.32 KB 116.1 KB 36.35 KB 36.54 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.3% +0.3% 939.12 KB 941.76 KB 207.42 KB 207.94 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-unstable-fizz.browser.production.min.js 0.0% 🔺+0.1% 1.2 KB 1.2 KB 701 B 702 B 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.production.min.js 0.0% 🔺+0.2% 1.04 KB 1.04 KB 632 B 633 B NODE_PROD
react-dom.development.js +0.3% +0.2% 914.99 KB 917.59 KB 207.39 KB 207.89 KB UMD_DEV
react-dom.production.min.js 🔺+0.7% 🔺+0.6% 111.71 KB 112.5 KB 36.02 KB 36.22 KB UMD_PROD
react-dom.profiling.min.js +0.7% +0.4% 115.12 KB 115.91 KB 37.08 KB 37.23 KB UMD_PROFILING
react-dom.development.js +0.3% +0.2% 909.08 KB 911.68 KB 205.71 KB 206.21 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.7% 🔺+0.5% 111.68 KB 112.47 KB 35.39 KB 35.56 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% 0.0% 20.13 KB 20.13 KB 7.5 KB 7.51 KB NODE_PROD
ReactDOM-prod.js 🔺+0.6% 🔺+0.5% 372 KB 374.11 KB 68.15 KB 68.46 KB FB_WWW_PROD
ReactDOM-profiling.js +0.6% +0.4% 377.55 KB 379.74 KB 69.21 KB 69.5 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
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 60.71 KB 60.71 KB 15.85 KB 15.85 KB UMD_DEV
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-dom-unstable-fizz.node.development.js 0.0% +0.1% 3.87 KB 3.87 KB 1.51 KB 1.51 KB NODE_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.1% 1.1 KB 1.1 KB 667 B 668 B NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.4% +0.3% 657.27 KB 659.87 KB 143.12 KB 143.58 KB UMD_DEV
react-art.production.min.js 🔺+0.8% 🔺+0.6% 101.93 KB 102.72 KB 31.17 KB 31.34 KB UMD_PROD
react-art.development.js +0.4% +0.4% 587.95 KB 590.55 KB 125.67 KB 126.13 KB NODE_DEV
react-art.production.min.js 🔺+1.2% 🔺+0.9% 66.94 KB 67.73 KB 20.4 KB 20.59 KB NODE_PROD
ReactART-dev.js +0.4% +0.4% 603.18 KB 605.82 KB 125.4 KB 125.88 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.9% 🔺+0.8% 225.92 KB 228.02 KB 38.47 KB 38.78 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.8% 🔺+0.7% 269.9 KB 272 KB 46.26 KB 46.57 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +0.8% +0.7% 278.4 KB 280.59 KB 47.8 KB 48.15 KB RN_OSS_PROFILING
ReactFabric-prod.js 🔺+0.8% 🔺+0.7% 261.69 KB 263.79 KB 44.95 KB 45.28 KB RN_OSS_PROD
ReactFabric-profiling.js +0.8% +0.7% 270.44 KB 272.63 KB 46.47 KB 46.81 KB RN_OSS_PROFILING
ReactFabric-dev.js +0.4% +0.3% 742.49 KB 745.13 KB 156.9 KB 157.37 KB RN_FB_DEV
ReactFabric-prod.js 🔺+0.8% 🔺+0.7% 261.7 KB 263.8 KB 44.96 KB 45.29 KB RN_FB_PROD
ReactNativeRenderer-dev.js +0.4% +0.3% 735.89 KB 738.53 KB 155.72 KB 156.19 KB RN_OSS_DEV
ReactFabric-profiling.js +0.8% +0.7% 270.44 KB 272.62 KB 46.48 KB 46.82 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js +0.4% +0.3% 736.05 KB 738.69 KB 155.81 KB 156.28 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+0.8% 🔺+0.7% 269.9 KB 272 KB 46.27 KB 46.58 KB RN_FB_PROD
ReactNativeRenderer-profiling.js +0.8% +0.7% 278.39 KB 280.58 KB 47.81 KB 48.15 KB RN_FB_PROFILING
ReactFabric-dev.js +0.4% +0.3% 742.32 KB 744.96 KB 156.83 KB 157.3 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.4% +0.4% 614.27 KB 616.91 KB 127.81 KB 128.3 KB FB_WWW_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.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.4% +0.4% 601.29 KB 603.89 KB 128.44 KB 128.92 KB UMD_DEV
react-test-renderer.production.min.js 🔺+1.2% 🔺+0.8% 68.88 KB 69.67 KB 21.18 KB 21.36 KB UMD_PROD
react-test-renderer.development.js +0.4% +0.4% 596.63 KB 599.22 KB 127.24 KB 127.71 KB NODE_DEV
react-test-renderer.production.min.js 🔺+1.2% 🔺+0.8% 68.57 KB 69.37 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.4% +0.4% 586.59 KB 589.19 KB 124.37 KB 124.87 KB NODE_DEV
react-reconciler.production.min.js 🔺+1.2% 🔺+0.8% 68.94 KB 69.73 KB 20.44 KB 20.61 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 +0.4% +0.4% 583.6 KB 586.2 KB 123.1 KB 123.6 KB NODE_DEV
react-reconciler-persistent.production.min.js 🔺+1.2% 🔺+0.8% 68.95 KB 69.74 KB 20.45 KB 20.61 KB NODE_PROD

Generated by 🚫 dangerJS against 100945b

@acdlite acdlite force-pushed the track-pending-and-suspended branch 2 times, most recently from 37c942e to 5d1fe07 Compare September 5, 2019 03:04
return (
firstSuspendedTime !== NoWork &&
(firstSuspendedTime >= expirationTime &&
lastSuspendedTime <= expirationTime)
Copy link
Contributor

@NE-SmallTown NE-SmallTown Sep 5, 2019

Choose a reason for hiding this comment

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

FYI, totally I think it's time to rename the name 'expirationTime' because it's been talked/discussed a few months, but for now, since it's a 'time' could we compare them through the 'time order'? I.e. from small to large (lastSuspendedTime <= expirationTime && expirationTime <= firstSuspendedTime)

if (lastPendingTime < expirationTime) {
// There's lower priority work. It might be unsuspended. Try rendering
// at that level immediately, while preserving the position in the queue.
return renderRoot.bind(null, root, lastPendingTime);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We're discussing this. Seems like this refactoring changed things.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be replaced by a prepareFreshStack in an update that happens during a yield.

If the current tree has already determined that it has remaining work at lower pri, we can use that info to eagerly throw to terminate the render and try at lower pri.

// as well start doing that eagerly.
// just going to try to recover at the pending time anyway so we might as
// well start doing that eagerly.
//
// Ideally we should be able to do this even for retries but we don't yet
// know if we're going to process an update which wants to commit earlier,
// and this path happens very early so it would happen too often. Instead,
// for that case, we'll wait until we complete.
if (workInProgressRootHasPendingPing) {
// We have a ping at this expiration. Let's restart to see if we get unblocked.
prepareFreshStack(root, expirationTime);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be removed (maybe) because there exists one in the ping function already.

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

6 participants