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

Revert risky work loop changes #16743 #16769

Merged
merged 1 commit into from
Sep 12, 2019

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Sep 12, 2019

I had some trouble landing #16743 internally. I'm not sure yet if they are transient issues or a problem with the PR.

Just to be safe, I'm going to revert this to unblock the www sync and then only merge it back once this successfully lands downstream. Should be fine since it doesn't overlap with any of our pending PRs.

This reverts commit ab4951f.

* Track "pending" and "suspended" ranges

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.

* Get next expiration time from FiberRoot

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.

* Don't bind expiration time to render callback

This is a fragile pattern because there's only meant to be a single
task per root, running at a single expiration time. Instead of binding
the expiration time to the render task, or closing over it, we should
determine the correct expiration time to work on using fields we
store on the root object itself.

This removes the "return a continuation" pattern from the
`renderRoot` function. Continuation handling is now handled by
the wrapper function, which I've renamed from `runRootCallback` to
`performWorkOnRoot`. That function is merely an entry point to
`renderRoot`, so I've also removed the callback argument.

So to sum up, at at the beginning of each task, `performWorkOnRoot`
determines which expiration time to work on, then calls `renderRoot`.
And before exiting, it checks if it needs to schedule another task.

* Update error recovery test to match new semantics

* Remove `lastPendingTime` field

It's no longer used anywhere

* Restart on update to already suspended root

If the work-in-progress root already suspended with a delay, then the
current render definitely won't finish. We should interrupt the render
and switch to the incoming update.

* Restart on suspend if return path has an update

Similar to the previous commit, if we suspend with a delay, and
something in the return path has a pending update, we should abort
the current render and switch to the update instead.

* Track the next unprocessed level globally

Instead of backtracking the return path. The main advantage over the
backtracking approach is that we don't have to backtrack from the source
fiber. (The main disadvantages are that it requires another module-level
variable, and that it could include updates from unrelated
sibling paths.)

* Re-arrange slightly to prevent refactor hazard

It should not be possible to perform any work on a root without
calling `ensureRootIsScheduled` before exiting. Otherwise, we could
fail to schedule a callback for pending work and the app could freeze.

To help prevent a future refactor from introducing such a bug, this
change makes it so that `renderRoot` is always wrapped in try-finally,
and the `finally` block calls `ensureRootIsScheduled`.

* Remove recursive calls to `renderRoot`.

There are a few leftover cases where `renderRoot` is called recursively.
All of them are related to synchronously flushing work before its
expiration time.

We can remove these calls by tracking the last expired level on the
root, similar to what we do for other types of pending work, like pings.

* Remove argument from performSyncWorkOnRoot

Read the expiration time from the root, like we do
in performConcurrentWorkOnRoot.
@sizebot
Copy link

sizebot commented Sep 12, 2019

ReactDOM: size: 0.0%, gzip: 0.0%

Details of bundled changes.

Comparing: 8f03109...f6d1f20

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js -1.1% -0.9% 117.12 KB 115.83 KB 36.86 KB 36.52 KB NODE_PROFILING
ReactDOM-dev.js -0.8% -0.8% 953.92 KB 946.69 KB 210.6 KB 208.93 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.46 KB 57.46 KB 15.82 KB 15.82 KB UMD_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.78 KB 3.78 KB 1.53 KB 1.53 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.1% 1.2 KB 1.2 KB 701 B 700 B UMD_PROD
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.development.js -0.8% -0.8% 929.7 KB 922.46 KB 210.01 KB 208.36 KB UMD_DEV
react-dom.production.min.js -1.1% -0.9% 113.47 KB 112.27 KB 36.55 KB 36.24 KB UMD_PROD
react-dom.profiling.min.js -1.1% -1.0% 116.99 KB 115.66 KB 37.55 KB 37.17 KB UMD_PROFILING
react-dom.development.js -0.8% -0.8% 923.78 KB 916.55 KB 208.38 KB 206.75 KB NODE_DEV
react-dom.production.min.js -1.1% -0.8% 113.4 KB 112.2 KB 35.86 KB 35.56 KB NODE_PROD
ReactDOM-prod.js -1.3% -1.0% 379.97 KB 374.97 KB 69.28 KB 68.58 KB FB_WWW_PROD
ReactDOM-profiling.js -1.4% -1.1% 386.01 KB 380.45 KB 70.38 KB 69.61 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
ReactDOMServer-dev.js 0.0% -0.0% 142.55 KB 142.55 KB 35.71 KB 35.71 KB FB_WWW_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% -0.1% 1.1 KB 1.1 KB 667 B 666 B NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js -1.1% -1.0% 666.68 KB 659.46 KB 144.91 KB 143.41 KB UMD_DEV
react-art.production.min.js -1.2% -1.0% 103.24 KB 102.02 KB 31.49 KB 31.18 KB UMD_PROD
react-art.development.js -1.2% -1.2% 597.35 KB 590.13 KB 127.49 KB 125.96 KB NODE_DEV
react-art.production.min.js -1.8% -1.5% 68.25 KB 67.02 KB 20.69 KB 20.38 KB NODE_PROD
ReactART-dev.js -1.2% -1.2% 612.66 KB 605.45 KB 127.26 KB 125.71 KB FB_WWW_DEV
ReactART-prod.js -2.2% -1.8% 231.12 KB 226.13 KB 39.24 KB 38.56 KB FB_WWW_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-prod.js -1.8% -1.7% 274.92 KB 269.86 KB 47.11 KB 46.31 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js -2.1% -1.6% 284.23 KB 278.38 KB 48.68 KB 47.9 KB RN_OSS_PROFILING
ReactFabric-prod.js -1.9% -1.5% 266.68 KB 261.61 KB 45.68 KB 45.01 KB RN_OSS_PROD
ReactFabric-profiling.js -2.1% -1.7% 276.38 KB 270.47 KB 47.38 KB 46.6 KB RN_OSS_PROFILING
ReactFabric-dev.js -1.0% -1.0% 751.86 KB 744.64 KB 158.87 KB 157.25 KB RN_FB_DEV
ReactFabric-prod.js -1.9% -1.5% 266.68 KB 261.61 KB 45.69 KB 45.03 KB RN_FB_PROD
ReactNativeRenderer-dev.js -1.0% -1.0% 745.25 KB 738.03 KB 157.7 KB 156.07 KB RN_OSS_DEV
ReactFabric-profiling.js -2.1% -1.7% 276.38 KB 270.46 KB 47.39 KB 46.61 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js -1.0% -1.0% 745.41 KB 738.19 KB 157.78 KB 156.15 KB RN_FB_DEV
ReactNativeRenderer-prod.js -1.8% -1.7% 274.92 KB 269.85 KB 47.12 KB 46.32 KB RN_FB_PROD
ReactNativeRenderer-profiling.js -2.1% -1.6% 284.22 KB 278.37 KB 48.69 KB 47.91 KB RN_FB_PROFILING
ReactFabric-dev.js -1.0% -1.0% 751.69 KB 744.47 KB 158.79 KB 157.17 KB RN_OSS_DEV

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactTestRenderer-dev.js -1.2% -1.2% 623.68 KB 616.47 KB 129.68 KB 128.12 KB FB_WWW_DEV
react-test-renderer.development.js -1.2% -1.2% 610.7 KB 603.48 KB 130.26 KB 128.73 KB UMD_DEV
react-test-renderer.production.min.js -1.8% -1.6% 70.19 KB 68.96 KB 21.52 KB 21.17 KB UMD_PROD
react-test-renderer.development.js -1.2% -1.2% 606.03 KB 598.81 KB 129.08 KB 127.53 KB NODE_DEV
react-test-renderer.production.min.js -1.8% -1.5% 69.88 KB 68.65 KB 21.19 KB 20.89 KB NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js -1.2% -1.3% 596.04 KB 588.81 KB 126.28 KB 124.68 KB NODE_DEV
react-reconciler.production.min.js -1.7% -1.3% 70.33 KB 69.13 KB 20.75 KB 20.47 KB NODE_PROD
react-reconciler-persistent.development.js -1.2% -1.3% 593.05 KB 585.81 KB 125.03 KB 123.42 KB NODE_DEV
react-reconciler-persistent.production.min.js -1.7% -1.3% 70.34 KB 69.14 KB 20.75 KB 20.48 KB NODE_PROD

Generated by 🚫 dangerJS against f6d1f20

@acdlite acdlite merged commit a7dabcb into facebook:master Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants