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

[Flare] Rework the responder dispatching/batching mechanism #16334

Merged
merged 3 commits into from
Aug 19, 2019

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Aug 9, 2019

We want to change the event system so it is possible to handle and manage ownership/propagation of event responders as we process the fiber tree. In order to do this, we need to change how the current event responder system works so that events that are queued to dispatch happen after the processing of each individual responder, rather than at the end.

Previously, we built up an array of all user events that needed to be dispatched, along with their priority and dispatched them all together. This made it impossible for user events to have effects that make it possible to control propagation and ownership though, as by this stage, we've already processed the responders. To illustrate this:

Responder A
  ->
    Responder B
      ->
        Responder C

Old Model:

If a native event happens and Responder C gets activated, we then bubble to Responder B and then to Responder A. Along the way, each responder might dispatchEvent, so we'd store the user events in an array. Once all Responders A, B, C have been handled we then flush all the events we've collected.

New Model:

If a native event happens and Responder C gets activated, we then bubble to Responder B and then to Responder A. Along the way, each responder might dispatchEvent, if so, we now dispatch the user events at that point, rather than having to queue them up to flush at the end. We are able to do this by wrapping the entire event process in batchedEventUpdates and having a dedicated event that sets a flag for when we're in the process of executing a user event. The priority logic from before remains unchanged because of these tweaks.

I also removed the global ownership model, as this new mechanism allows for a much more refined approach that simply globally saying a responder is the only owner. It also conflicts with how this new mechanism works.

@sizebot
Copy link

sizebot commented Aug 9, 2019

Details of bundled changes.

Comparing: e89c19d...f7375c5

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js -0.0% +0.1% 115.03 KB 115.03 KB 36.28 KB 36.31 KB NODE_PROFILING
react-dom-server.browser.development.js 0.0% 0.0% 140.04 KB 140.04 KB 36.79 KB 36.79 KB UMD_DEV
ReactDOM-dev.js -0.3% -0.3% 934.45 KB 931.33 KB 206.83 KB 206.29 KB FB_WWW_DEV
react-dom-test-utils.production.min.js 0.0% 🔺+0.1% 11.2 KB 11.2 KB 4.15 KB 4.15 KB 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-test-utils.production.min.js 0.0% 0.0% 10.98 KB 10.98 KB 4.08 KB 4.08 KB NODE_PROD
react-dom.development.js -0.3% -0.2% 909.96 KB 906.86 KB 206.57 KB 206.09 KB UMD_DEV
react-dom.production.min.js -0.0% -0.0% 111.43 KB 111.43 KB 35.91 KB 35.91 KB UMD_PROD
react-dom.profiling.min.js -0.0% 0.0% 114.83 KB 114.83 KB 36.94 KB 36.95 KB UMD_PROFILING
react-dom.development.js -0.3% -0.2% 904.25 KB 901.16 KB 204.98 KB 204.47 KB NODE_DEV
react-dom.production.min.js -0.0% 0.0% 111.4 KB 111.4 KB 35.34 KB 35.34 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% 0.0% 20.01 KB 20.01 KB 7.48 KB 7.48 KB NODE_PROD
ReactDOM-prod.js -0.8% -0.8% 370.96 KB 367.86 KB 68.07 KB 67.5 KB FB_WWW_PROD
ReactDOM-profiling.js -0.8% -0.8% 376.04 KB 372.94 KB 69.12 KB 68.54 KB FB_WWW_PROFILING
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.71 KB 60.71 KB 15.85 KB 15.84 KB UMD_DEV
ReactDOMServer-prod.js 0.0% 0.0% 48.02 KB 48.02 KB 11.02 KB 11.03 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-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.2% 1.1 KB 1.1 KB 666 B 667 B NODE_PROD

react-events

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-events-focus.development.js -2.0% -0.8% 11.18 KB 10.96 KB 2.37 KB 2.35 KB UMD_DEV
react-events-press.development.js -0.5% -0.3% 20.49 KB 20.38 KB 4.77 KB 4.75 KB UMD_DEV
react-events-focus.production.min.js -2.7% -1.3% 4.22 KB 4.1 KB 1.4 KB 1.38 KB UMD_PROD
ReactEventsHover-dev.js -1.1% -0.8% 6.84 KB 6.77 KB 1.53 KB 1.51 KB FB_WWW_DEV
react-events-press.production.min.js -1.0% -0.6% 6.91 KB 6.84 KB 2.61 KB 2.59 KB UMD_PROD
ReactEventsScroll-dev.js -1.2% -1.0% 5.84 KB 5.77 KB 1.56 KB 1.54 KB FB_WWW_DEV
react-events-swipe.development.js -8.4% -6.3% 6.57 KB 6.01 KB 1.73 KB 1.62 KB UMD_DEV
react-events-context-menu.production.min.js 0.0% 🔺+0.1% 1.39 KB 1.39 KB 725 B 726 B UMD_PROD
ReactEventsDrag-dev.js -11.3% -7.7% 5.77 KB 5.12 KB 1.56 KB 1.44 KB FB_WWW_DEV
react-events-swipe.production.min.js -7.1% -7.1% 2.63 KB 2.44 KB 1.19 KB 1.11 KB UMD_PROD
ReactEventsDrag-prod.js -11.9% -7.6% 4.35 KB 3.84 KB 1.3 KB 1.21 KB FB_WWW_PROD
react-events-swipe.development.js -8.7% -6.6% 6.38 KB 5.83 KB 1.69 KB 1.58 KB NODE_DEV
react-events-swipe.production.min.js -7.6% -7.8% 2.45 KB 2.26 KB 1.14 KB 1.05 KB NODE_PROD
react-events-hover.development.js -1.1% -0.9% 7.08 KB 7.01 KB 1.56 KB 1.55 KB UMD_DEV
react-events-scroll.development.js -1.1% -1.2% 5.9 KB 5.84 KB 1.59 KB 1.57 KB UMD_DEV
react-events-hover.production.min.js -1.2% -1.5% 3.15 KB 3.11 KB 1.14 KB 1.12 KB UMD_PROD
react-events-scroll.production.min.js -1.5% -1.3% 2.39 KB 2.35 KB 1.09 KB 1.07 KB UMD_PROD
ReactEventsSwipe-dev.js -8.0% -6.5% 6.57 KB 6.04 KB 1.71 KB 1.6 KB FB_WWW_DEV
ReactEventsSwipe-prod.js -7.6% -5.1% 5.2 KB 4.8 KB 1.46 KB 1.39 KB FB_WWW_PROD
react-events-hover.development.js -1.1% -0.8% 6.9 KB 6.83 KB 1.51 KB 1.5 KB NODE_DEV
react-events-scroll.development.js -1.2% -0.9% 5.72 KB 5.65 KB 1.53 KB 1.52 KB NODE_DEV
react-events-hover.production.min.js -1.3% -1.3% 2.97 KB 2.93 KB 1.08 KB 1.06 KB NODE_PROD
react-events-scroll.production.min.js -1.4% -1.4% 2.2 KB 2.17 KB 1.02 KB 1 KB NODE_PROD
ReactEventsHover-prod.js -1.3% -1.1% 6.03 KB 5.95 KB 1.39 KB 1.37 KB FB_WWW_PROD
ReactEventsScroll-prod.js -0.8% -1.2% 4.48 KB 4.44 KB 1.33 KB 1.31 KB FB_WWW_PROD
react-events-focus.development.js -2.0% -0.8% 11 KB 10.77 KB 2.33 KB 2.31 KB NODE_DEV
react-events-press.development.js -0.5% -0.3% 20.3 KB 20.2 KB 4.72 KB 4.7 KB NODE_DEV
react-events-focus.production.min.js -2.8% -1.4% 4.04 KB 3.93 KB 1.33 KB 1.31 KB NODE_PROD
react-events-press.production.min.js -1.0% -0.5% 6.73 KB 6.66 KB 2.54 KB 2.53 KB NODE_PROD
react-events-drag.development.js -11.5% -7.5% 5.92 KB 5.24 KB 1.66 KB 1.53 KB UMD_DEV
react-events-keyboard.development.js 0.0% -0.1% 4.32 KB 4.32 KB 1.64 KB 1.64 KB UMD_DEV
react-events-drag.production.min.js -9.5% -6.6% 2.48 KB 2.25 KB 1.14 KB 1.07 KB UMD_PROD
ReactEventsFocus-dev.js -2.0% -0.8% 10.94 KB 10.72 KB 2.35 KB 2.33 KB FB_WWW_DEV
ReactEventsPress-dev.js -0.5% -0.3% 21.06 KB 20.96 KB 4.9 KB 4.88 KB FB_WWW_DEV
ReactEventsFocus-prod.js -3.2% -1.2% 8.33 KB 8.07 KB 1.71 KB 1.69 KB FB_WWW_PROD
ReactEventsPress-prod.js -1.2% -0.5% 15.77 KB 15.59 KB 3.51 KB 3.49 KB FB_WWW_PROD
react-events-drag.development.js -8.9% -5.2% 7.68 KB 7 KB 2.33 KB 2.21 KB NODE_DEV
react-events-drag.production.min.js -7.6% -5.2% 3.12 KB 2.88 KB 1.45 KB 1.37 KB NODE_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactFabric-prod.js -0.0% -0.0% 261.42 KB 261.41 KB 44.88 KB 44.88 KB RN_OSS_PROD
ReactFabric-profiling.js -0.0% -0.0% 270.08 KB 270.07 KB 46.41 KB 46.41 KB RN_OSS_PROFILING
ReactFabric-dev.js -0.4% -0.3% 736.59 KB 733.5 KB 155.94 KB 155.52 KB RN_FB_DEV
ReactFabric-prod.js -0.0% -0.0% 261.42 KB 261.41 KB 44.9 KB 44.9 KB RN_FB_PROD
ReactNativeRenderer-dev.js -0.0% -0.0% 726.95 KB 726.95 KB 154.36 KB 154.35 KB RN_OSS_DEV
ReactFabric-profiling.js -0.0% -0.0% 270.08 KB 270.07 KB 46.42 KB 46.42 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js -0.0% -0.0% 727.11 KB 727.11 KB 154.43 KB 154.43 KB RN_FB_DEV
ReactFabric-dev.js -0.4% -0.3% 736.42 KB 733.33 KB 155.87 KB 155.45 KB RN_OSS_DEV

Generated by 🚫 dangerJS

@trueadm
Copy link
Contributor Author

trueadm commented Aug 19, 2019

@necolas @acdlite @sebmarkbage Would be good to get a review on this PR when you folks have a chance.

@trueadm trueadm merged commit dce430a into facebook:master Aug 19, 2019
@trueadm trueadm deleted the flare-dispatch-redesign branch August 19, 2019 18:22
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