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

Decouple update priority tracking from Scheduler package #19121

Merged
merged 36 commits into from
Jul 6, 2020

Conversation

rickhanlonii
Copy link
Member

@rickhanlonii rickhanlonii commented Jun 12, 2020

Summary

We'd like to remove a dependency on the Scheduler priority from React internals by replacing it with a currentLanePriority which will be tracked inside React. This PR starts currentLanePriority implementation by setting it everywhere that the scheduler priority is set, and then logging mismatches as they occur.

The next step is to investigate mismatches and handle them appropriately.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 12, 2020

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 4294152:

Sandbox Source
React Configuration

Copy link
Collaborator

@sebmarkbage sebmarkbage left a comment

Choose a reason for hiding this comment

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

We have way too many execution contexts. Scheduler, execution context, suspense config and now this. I think we need to take a step back and come up with a plan for how we get rid of the overhead. Like the existing runWithPriority with a new closure just to set one state is completely unacceptable overhead, so we shouldn't follow that lead.

I understand that this is just one step along refactoring but I worry that we're refactoring to has too much inherent complexity.

Do we have a plan for what we want to do with 1) execution context, 2) runWithPriority and 3) how we can avoid special cases like priorityLevel < UserBlockingPriority all over the code base?

(this is more of a comment to @acdlite ofc :) )

@sebmarkbage
Copy link
Collaborator

sebmarkbage commented Jun 12, 2020

For perspective the way I look at setState is that in an optimal reactive system it's essentially this:

setState = (reducer) => {
  inst.nextState = reducer(inst.nextState);
  if (!inst.isDirty) {
    inst.isDirty = true;
    dirtyInstances.push(inst);
  }
}

The goal is to get close to this, because if we're not close then the system doesn't pay for itself, but we're very far away from this for a simple state change atm. I think we might need to do something more radical.

@acdlite
Copy link
Collaborator

acdlite commented Jun 12, 2020

Do we have a plan for what we want to do with 1) execution context, 2) runWithPriority and 3) how we can avoid special cases like priorityLevel < UserBlockingPriority all over the code base?

This PR is meant to address 2 and 3. It doesn't in the current state but that's one of the goals.

@acdlite
Copy link
Collaborator

acdlite commented Jun 12, 2020

I think we agree on the final end state. The goals for this first step are a bit confusing and contradictory so I'll list them here:

  • The main goal is to decouple the Scheduler priority from React update priority. It should be possible for us to control the priority of updates without going through Scheduler. This helps not only with coupling, but also means (in the future) we can avoid the overhead of runWithPriority. All of our APIs that change the priority already have a try/finally block; we can mutate the current update priority directly without a wrapper function.
  • We can't remove runWithPriority entirely without a semantic change. So in this first step, we'll keep all the existing runWithPriority calls. We'll start removing them behind the feature flag Rick has added (could maybe move that to a separate PR).
  • Similarly, we need to keep the getCurrentPriorityLevel check at the end of the requestUpdateLane algorithm so that outside runWithPriority calls still affect update priority.

Once the decoupling is complete, then we can move on to actually removing the extra wrappers. This will require some semantic changes and we'll need to audit www for existing uses.

@acdlite
Copy link
Collaborator

acdlite commented Jun 12, 2020

This is a really great first React PR!

@acdlite
Copy link
Collaborator

acdlite commented Jun 12, 2020

Sorry, I guess I mean first reconciler PR. I know it's not your first React PR ever :D

@sizebot
Copy link

sizebot commented Jun 16, 2020

Details of bundled changes.

Comparing: c3e42a9...4294152

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.4% +0.3% 905.59 KB 908.77 KB 206.09 KB 206.67 KB NODE_DEV
ReactDOMForked-prod.js 🔺+0.7% 🔺+0.6% 388.02 KB 390.67 KB 72.46 KB 72.87 KB FB_WWW_PROD
react-dom-server.node.development.js 0.0% 0.0% 138.39 KB 138.39 KB 36.56 KB 36.56 KB NODE_DEV
react-dom.production.min.js 🔺+0.3% 🔺+0.6% 122.89 KB 123.23 KB 39.3 KB 39.53 KB NODE_PROD
ReactDOMForked-profiling.js +0.7% +0.6% 398.55 KB 401.21 KB 74.21 KB 74.62 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% 0.0% 144.55 KB 144.55 KB 36.75 KB 36.75 KB UMD_DEV
react-dom-server.node.production.min.js 0.0% 0.0% 20.68 KB 20.68 KB 7.66 KB 7.66 KB NODE_PROD
react-dom-test-utils.production.min.js 0.0% 0.0% 10.35 KB 10.35 KB 4.07 KB 4.07 KB UMD_PROD
ReactDOMTesting-dev.js +0.3% +0.3% 946.46 KB 949.71 KB 212.28 KB 212.94 KB FB_WWW_DEV
ReactDOMTesting-prod.js 🔺+0.4% 🔺+0.5% 394.84 KB 396.58 KB 74.83 KB 75.18 KB FB_WWW_PROD
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 5.61 KB 5.61 KB 1.86 KB 1.87 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 10.2 KB 10.2 KB 3.99 KB 3.99 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 5.36 KB 5.36 KB 1.8 KB 1.81 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.3% 1.17 KB 1.17 KB 667 B 669 B NODE_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.1% 1.2 KB 1.2 KB 706 B 707 B UMD_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 4.87 KB 4.87 KB 1.7 KB 1.71 KB NODE_DEV
react-dom.development.js +0.3% +0.3% 951.27 KB 954.58 KB 208.52 KB 209.13 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1.01 KB 1.01 KB 616 B 618 B NODE_PROD
react-dom.production.min.js 🔺+0.3% 🔺+0.2% 122.73 KB 123.07 KB 40.13 KB 40.22 KB UMD_PROD
react-dom.profiling.min.js +0.3% +0.4% 126.68 KB 127.02 KB 41.3 KB 41.48 KB UMD_PROFILING
ReactDOMForked-dev.js +0.4% +0.3% 966.6 KB 970.42 KB 216.22 KB 216.93 KB FB_WWW_DEV
react-dom.profiling.min.js +0.3% +0.6% 127.01 KB 127.35 KB 40.51 KB 40.75 KB NODE_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 20.34 KB 20.34 KB 7.52 KB 7.52 KB UMD_PROD
ReactDOM-dev.js +0.3% +0.3% 973.71 KB 976.91 KB 217.52 KB 218.13 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.7% 🔺+0.6% 388.21 KB 390.88 KB 72.47 KB 72.88 KB FB_WWW_PROD
react-dom-server.browser.development.js 0.0% 0.0% 137.12 KB 137.12 KB 36.31 KB 36.31 KB NODE_DEV
ReactDOM-profiling.js +0.7% +0.6% 398.75 KB 401.41 KB 74.22 KB 74.63 KB FB_WWW_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 20.26 KB 20.26 KB 7.51 KB 7.51 KB NODE_PROD
ReactDOMServer-dev.js 0.0% 0.0% 142.62 KB 142.62 KB 36.25 KB 36.25 KB FB_WWW_DEV
ReactDOMServer-prod.js 0.0% 0.0% 46.58 KB 46.58 KB 10.9 KB 10.9 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% 0.0% 55.53 KB 55.53 KB 15.37 KB 15.37 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.2% 684.6 KB 685.46 KB 148.14 KB 148.39 KB RN_FB_DEV
ReactFabric-dev.js +0.1% +0.2% 665.32 KB 666.18 KB 143.49 KB 143.74 KB RN_FB_DEV
ReactNativeRenderer-dev.js +0.1% +0.2% 679.72 KB 680.58 KB 147.38 KB 147.63 KB RN_OSS_DEV
ReactFabric-prod.js 0.0% 0.0% 265.82 KB 265.85 KB 47.01 KB 47.02 KB RN_FB_PROD
ReactNativeRenderer-prod.js 0.0% 0.0% 272.15 KB 272.17 KB 48.29 KB 48.31 KB RN_OSS_PROD
ReactFabric-profiling.js 0.0% 0.0% 277.36 KB 277.38 KB 49.23 KB 49.24 KB RN_FB_PROFILING
ReactNativeRenderer-profiling.js 0.0% 0.0% 283.65 KB 283.68 KB 50.49 KB 50.51 KB RN_OSS_PROFILING
ReactNativeRenderer-prod.js 0.0% 0.0% 272.1 KB 272.13 KB 48.27 KB 48.29 KB RN_FB_PROD
ReactNativeRenderer-profiling.js 0.0% 0.0% 283.6 KB 283.63 KB 50.47 KB 50.49 KB RN_FB_PROFILING
ReactFabric-dev.js +0.1% +0.2% 660.43 KB 661.3 KB 142.72 KB 142.97 KB RN_OSS_DEV
ReactFabric-prod.js 0.0% 0.0% 265.86 KB 265.89 KB 47.02 KB 47.03 KB RN_OSS_PROD
ReactFabric-profiling.js 0.0% 0.0% 277.4 KB 277.42 KB 49.24 KB 49.26 KB RN_OSS_PROFILING

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactART-prod.js 0.0% 0.0% 240.46 KB 240.49 KB 42.48 KB 42.48 KB FB_WWW_PROD
react-art.development.js +0.1% +0.2% 688.28 KB 689.13 KB 145.87 KB 146.1 KB UMD_DEV
react-art.production.min.js 🔺+0.1% 🔺+0.1% 112.45 KB 112.52 KB 34.79 KB 34.82 KB UMD_PROD
react-art.development.js +0.1% +0.2% 589.77 KB 590.61 KB 128.06 KB 128.31 KB NODE_DEV
react-art.production.min.js 0.0% 0.0% 77.41 KB 77.42 KB 23.92 KB 23.93 KB NODE_PROD
ReactART-dev.js +0.1% +0.2% 618.29 KB 619.1 KB 131.77 KB 132.04 KB FB_WWW_DEV

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer-shallow.production.min.js 0.0% -0.0% 12.74 KB 12.74 KB 3.97 KB 3.97 KB UMD_PROD
react-test-renderer.development.js +0.1% +0.2% 604.67 KB 605.53 KB 127.13 KB 127.35 KB UMD_DEV
react-test-renderer.production.min.js 0.0% 0.0% 76.7 KB 76.71 KB 24 KB 24 KB UMD_PROD
react-test-renderer.development.js +0.1% +0.2% 576.11 KB 576.94 KB 125.64 KB 125.86 KB NODE_DEV
react-test-renderer.production.min.js 0.0% 0.0% 76.53 KB 76.53 KB 23.69 KB 23.7 KB NODE_PROD
ReactTestRenderer-dev.js +0.1% +0.2% 598.93 KB 599.8 KB 128.42 KB 128.68 KB FB_WWW_DEV
ReactTestRenderer-dev.js +0.1% +0.2% 592.5 KB 593.36 KB 128.26 KB 128.52 KB RN_FB_DEV
react-test-renderer-shallow.development.js 0.0% -0.0% 39.17 KB 39.17 KB 9.58 KB 9.58 KB UMD_DEV

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.4% +0.4% 647.6 KB 650.5 KB 138.17 KB 138.71 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.4% 🔺+0.7% 87.2 KB 87.53 KB 26.66 KB 26.84 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

ReactDOM: size: 0.0%, gzip: 0.0%

Size changes (experimental)

Generated by 🚫 dangerJS against 4294152

@sizebot
Copy link

sizebot commented Jun 16, 2020

Details of bundled changes.

Comparing: c3e42a9...4294152

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.1% +0.2% 875.16 KB 876.46 KB 200.55 KB 200.86 KB NODE_DEV
ReactDOMForked-prod.js 🔺+0.7% 🔺+0.5% 399.2 KB 401.86 KB 74.02 KB 74.4 KB FB_WWW_PROD
react-dom-server.node.development.js 0.0% 0.0% 136.88 KB 136.88 KB 36.35 KB 36.35 KB NODE_DEV
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 118.42 KB 118.5 KB 38.04 KB 38.08 KB NODE_PROD
ReactDOMForked-profiling.js +0.6% +0.5% 409.8 KB 412.45 KB 75.79 KB 76.17 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% 0.0% 142.96 KB 142.96 KB 36.55 KB 36.55 KB UMD_DEV
react-dom-server.node.production.min.js 0.0% 0.0% 20.22 KB 20.22 KB 7.59 KB 7.59 KB NODE_PROD
react-dom-test-utils.production.min.js 0.0% 0.0% 10.34 KB 10.34 KB 4.06 KB 4.06 KB UMD_PROD
ReactDOMTesting-dev.js +0.3% +0.3% 974.5 KB 977.75 KB 218.14 KB 218.82 KB FB_WWW_DEV
ReactDOMTesting-prod.js 🔺+0.4% 🔺+0.4% 408.1 KB 409.83 KB 76.75 KB 77.09 KB FB_WWW_PROD
react-dom-test-utils.production.min.js 0.0% -0.0% 10.19 KB 10.19 KB 3.98 KB 3.98 KB NODE_PROD
react-dom.development.js +0.1% +0.2% 919.48 KB 920.83 KB 202.92 KB 203.23 KB UMD_DEV
react-dom.production.min.js 🔺+0.1% 🔺+0.2% 118.33 KB 118.41 KB 38.77 KB 38.84 KB UMD_PROD
react-dom.profiling.min.js +0.1% +0.2% 122.23 KB 122.31 KB 39.91 KB 39.99 KB UMD_PROFILING
ReactDOMForked-dev.js +0.4% +0.3% 992.15 KB 995.96 KB 221.39 KB 222.15 KB FB_WWW_DEV
react-dom.profiling.min.js +0.1% +0.1% 122.48 KB 122.56 KB 39.21 KB 39.26 KB NODE_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 19.88 KB 19.88 KB 7.44 KB 7.45 KB UMD_PROD
ReactDOM-dev.js +0.3% +0.3% 999.26 KB 1002.46 KB 222.68 KB 223.35 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.7% 🔺+0.5% 399.4 KB 402.06 KB 74.03 KB 74.42 KB FB_WWW_PROD
react-dom-server.browser.development.js 0.0% 0.0% 135.61 KB 135.61 KB 36.1 KB 36.1 KB NODE_DEV
ReactDOM-profiling.js +0.6% +0.5% 409.99 KB 412.66 KB 75.8 KB 76.19 KB FB_WWW_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 19.8 KB 19.8 KB 7.43 KB 7.43 KB NODE_PROD
ReactDOMServer-dev.js 0.0% 0.0% 146.66 KB 146.66 KB 37.25 KB 37.25 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% 0.0% 55.52 KB 55.52 KB 15.36 KB 15.36 KB UMD_DEV

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactART-prod.js 0.0% 0.0% 247.6 KB 247.63 KB 43.76 KB 43.77 KB FB_WWW_PROD
react-art.development.js +0.1% +0.1% 666.12 KB 666.97 KB 141.82 KB 142.03 KB UMD_DEV
react-art.production.min.js 🔺+0.1% 🔺+0.1% 109.5 KB 109.57 KB 33.89 KB 33.93 KB UMD_PROD
react-art.development.js +0.1% +0.2% 568.52 KB 569.36 KB 124 KB 124.24 KB NODE_DEV
react-art.production.min.js 0.0% 0.0% 74.52 KB 74.53 KB 23.05 KB 23.06 KB NODE_PROD
ReactART-dev.js +0.1% +0.2% 628.3 KB 629.11 KB 133.79 KB 134.08 KB FB_WWW_DEV

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer-shallow.production.min.js 0.0% -0.0% 12.73 KB 12.73 KB 3.96 KB 3.96 KB UMD_PROD
react-test-renderer.development.js +0.1% +0.2% 604.65 KB 605.5 KB 127.11 KB 127.34 KB UMD_DEV
react-test-renderer.production.min.js 0.0% 0.0% 76.68 KB 76.69 KB 23.98 KB 23.99 KB UMD_PROD
react-test-renderer.development.js +0.1% +0.2% 576.08 KB 576.92 KB 125.63 KB 125.85 KB NODE_DEV
react-test-renderer.production.min.js 0.0% 0.0% 76.5 KB 76.51 KB 23.67 KB 23.69 KB NODE_PROD
ReactTestRenderer-dev.js +0.1% +0.2% 598.92 KB 599.78 KB 128.42 KB 128.68 KB FB_WWW_DEV
ReactTestRenderer-dev.js +0.1% +0.2% 592.48 KB 593.35 KB 128.26 KB 128.51 KB RN_FB_DEV
react-test-renderer-shallow.development.js 0.0% -0.0% 39.16 KB 39.16 KB 9.57 KB 9.57 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.2% 679.71 KB 680.57 KB 147.37 KB 147.62 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 0.0% 0.0% 272.13 KB 272.16 KB 48.28 KB 48.3 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js 0.0% 0.0% 283.64 KB 283.67 KB 50.48 KB 50.5 KB RN_OSS_PROFILING
ReactFabric-dev.js +0.1% +0.2% 660.42 KB 661.28 KB 142.72 KB 142.96 KB RN_OSS_DEV
ReactFabric-prod.js 0.0% 0.0% 265.85 KB 265.87 KB 47.01 KB 47.02 KB RN_OSS_PROD
ReactFabric-profiling.js 0.0% 0.0% 277.38 KB 277.41 KB 49.24 KB 49.25 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.5% +0.4% 623.98 KB 626.88 KB 133.64 KB 134.2 KB NODE_DEV
react-reconciler-reflection.development.js 0.0% 0.0% 16.69 KB 16.69 KB 4.98 KB 4.98 KB NODE_DEV
react-reconciler.production.min.js 🔺+0.4% 🔺+0.6% 83.87 KB 84.19 KB 25.76 KB 25.91 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

ReactDOM: size: 0.0%, gzip: 0.0%

Size changes (stable)

Generated by 🚫 dangerJS against 4294152

@acdlite acdlite changed the title Initial currentLanePriority implementation Decouple update priority tracking from Scheduler package Jun 25, 2020
@rickhanlonii rickhanlonii marked this pull request as ready for review June 26, 2020 05:03
@rickhanlonii
Copy link
Member Author

Published for review, this should be good to go now 👍

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.

5 participants