Skip to content

Remove Set bookkeeping for root events#19990

Merged
gaearon merged 8 commits intofacebook:masterfrom
gaearon:rm-dead
Oct 16, 2020
Merged

Remove Set bookkeeping for root events#19990
gaearon merged 8 commits intofacebook:masterfrom
gaearon:rm-dead

Conversation

@gaearon
Copy link
Copy Markdown
Collaborator

@gaearon gaearon commented Oct 9, 2020

See individual commits.

This removes some dead code now that we don't use eager listeners. Then this forks the code between createEventHandle and the normal subscriptions since they have slightly different needs. Finally, this removes the Set bookkeeping for root events only (but it's still needed for non-managed createEventHandle and for non-delegated codepath which I haven't changed). I've needed to slightly restructure the code to keep deduplicating selectionchange (by the document).

I think the end result is a bit simpler. It also slightly reduces the work per portal creation.

This function is only called when initializing roots/containers (where we skip non-delegated events) and in the createEventHandle path for non-DOM nodes (where we never hit this path because targetElement is null).
It doesn't need all of the logic that's needed for normal event path.

And the normal codepath doesn't use the last two arguments.
This changes a test to fail if we removed the event handler Sets. Previously, we didn't cover that.
… not overlap

This makes us confident that they're mutually exclusive and there is no duplication between them.
This is why we still need the Set bookkeeping. Adding a test for it.
Root events don't intersect with non-delegated bubbled events (so no need to deduplicate there). They also don't intersect with createEventHandle non-managed events (because those don't go on the DOM elements). So we can remove the bookeeping because we already have code ensuring the eager subscriptions only run once per element.

I've moved the selectionchange special case outside, and added document-level deduplication for it alone.

Technically this might change the behavior of createEventHandle with selectionchange on the document, but we're not using that, and I'm not sure that behavior makes sense anyway.
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Oct 9, 2020
@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci Bot commented Oct 9, 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 a286fc2:

Sandbox Source
React Configuration

@sizebot
Copy link
Copy Markdown

sizebot commented Oct 9, 2020

Details of bundled changes.

Comparing: f46a80a...a286fc2

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js -0.1% -0.2% 873.22 KB 872.33 KB 200.01 KB 199.69 KB NODE_DEV
ReactDOMForked-prod.js 0.0% 🔺+0.1% 383.09 KB 383.26 KB 70.63 KB 70.68 KB FB_WWW_PROD
react-dom.production.min.js -0.1% -0.2% 117.88 KB 117.72 KB 38.01 KB 37.94 KB NODE_PROD
ReactDOMForked-profiling.js 0.0% +0.1% 397.63 KB 397.8 KB 73.19 KB 73.25 KB FB_WWW_PROFILING
react-dom-test-utils.production.min.js 0.0% -0.0% 13.7 KB 13.7 KB 5.31 KB 5.31 KB UMD_PROD
ReactDOMTesting-dev.js -0.0% -0.1% 939.77 KB 939.51 KB 210.69 KB 210.45 KB FB_WWW_DEV
ReactDOMTesting-prod.js 0.0% 🔺+0.1% 384.1 KB 384.28 KB 72.23 KB 72.3 KB FB_WWW_PROD
react-dom-test-utils.production.min.js 0.0% 0.0% 13.68 KB 13.68 KB 5.26 KB 5.26 KB NODE_PROD
react-dom.development.js -0.1% -0.2% 917.65 KB 916.73 KB 202.54 KB 202.22 KB UMD_DEV
react-dom.production.min.js -0.1% -0.2% 117.78 KB 117.62 KB 38.74 KB 38.64 KB UMD_PROD
react-dom.profiling.min.js -0.1% -0.1% 121.68 KB 121.52 KB 39.91 KB 39.87 KB UMD_PROFILING
ReactDOMForked-dev.js -0.0% -0.1% 987.23 KB 986.97 KB 218.62 KB 218.38 KB FB_WWW_DEV
react-dom.profiling.min.js -0.1% -0.2% 121.96 KB 121.8 KB 39.19 KB 39.12 KB NODE_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 19.88 KB 19.88 KB 7.46 KB 7.46 KB UMD_PROD
ReactDOM-dev.js -0.0% -0.1% 976.56 KB 976.3 KB 217.27 KB 217.02 KB FB_WWW_DEV
ReactDOM-prod.js 0.0% 🔺+0.1% 380.59 KB 380.76 KB 70.11 KB 70.17 KB FB_WWW_PROD
react-dom-server.browser.development.js 0.0% -0.0% 135.79 KB 135.79 KB 36.12 KB 36.12 KB NODE_DEV
ReactDOM-profiling.js 0.0% +0.1% 393.6 KB 393.77 KB 72.49 KB 72.55 KB FB_WWW_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 19.78 KB 19.78 KB 7.42 KB 7.42 KB NODE_PROD
ReactDOMServer-dev.js 0.0% -0.0% 145.44 KB 145.44 KB 37.28 KB 37.28 KB FB_WWW_DEV
ReactDOMServer-prod.js 0.0% -0.0% 47.3 KB 47.3 KB 11.04 KB 11.03 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% 0.0% 71.46 KB 71.46 KB 19.34 KB 19.34 KB UMD_DEV

ReactDOM: size: 0.0%, gzip: -0.0%

Size changes (stable)

Generated by 🚫 dangerJS against a286fc2

@sizebot
Copy link
Copy Markdown

sizebot commented Oct 9, 2020

Details of bundled changes.

Comparing: f46a80a...a286fc2

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js -0.1% -0.2% 908.77 KB 907.88 KB 206.56 KB 206.24 KB NODE_DEV
ReactDOMForked-prod.js 0.0% 🔺+0.1% 371.76 KB 371.93 KB 68.81 KB 68.88 KB FB_WWW_PROD
react-dom.production.min.js -0.1% -0.2% 122.42 KB 122.26 KB 39.35 KB 39.29 KB NODE_PROD
ReactDOMForked-profiling.js 0.0% +0.1% 386.26 KB 386.43 KB 71.38 KB 71.44 KB FB_WWW_PROFILING
react-dom-server.node.production.min.js 0.0% 0.0% 20.66 KB 20.66 KB 7.65 KB 7.65 KB NODE_PROD
react-dom-test-utils.production.min.js 0.0% -0.0% 13.71 KB 13.71 KB 5.32 KB 5.32 KB UMD_PROD
ReactDOMTesting-dev.js -0.0% -0.1% 911.43 KB 911.17 KB 205.21 KB 204.95 KB FB_WWW_DEV
ReactDOMTesting-prod.js 0.0% 🔺+0.1% 371.04 KB 371.21 KB 70.05 KB 70.1 KB FB_WWW_PROD
react-dom-test-utils.production.min.js 0.0% 0.0% 13.7 KB 13.7 KB 5.26 KB 5.27 KB NODE_PROD
react-dom.development.js -0.1% -0.1% 954.96 KB 954.04 KB 209.11 KB 208.8 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.2% 1.01 KB 1.01 KB 615 B 616 B NODE_PROD
react-dom.production.min.js -0.1% -0.2% 122.25 KB 122.09 KB 40.08 KB 40.01 KB UMD_PROD
react-dom.profiling.min.js -0.1% -0.1% 127.52 KB 127.36 KB 41.75 KB 41.7 KB UMD_PROFILING
ReactDOMForked-dev.js -0.0% -0.1% 961.65 KB 961.39 KB 213.87 KB 213.63 KB FB_WWW_DEV
react-dom.profiling.min.js -0.1% -0.2% 127.88 KB 127.71 KB 41.04 KB 40.96 KB NODE_PROFILING
ReactDOM-dev.js -0.0% -0.1% 950.98 KB 950.72 KB 212.59 KB 212.35 KB FB_WWW_DEV
ReactDOM-prod.js 0.0% 🔺+0.1% 369.33 KB 369.5 KB 68.34 KB 68.4 KB FB_WWW_PROD
react-dom-server.browser.development.js 0.0% 0.0% 137.3 KB 137.3 KB 36.33 KB 36.33 KB NODE_DEV
ReactDOM-profiling.js 0.0% +0.1% 382.29 KB 382.46 KB 70.74 KB 70.79 KB FB_WWW_PROFILING
react-dom-test-utils.development.js 0.0% 0.0% 71.47 KB 71.47 KB 19.35 KB 19.35 KB UMD_DEV

ReactDOM: size: 0.0%, gzip: -0.0%

Size changes (experimental)

Generated by 🚫 dangerJS against a286fc2

Copy link
Copy Markdown
Contributor

@trueadm trueadm left a comment

Choose a reason for hiding this comment

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

LGTM

@gaearon gaearon merged commit e9f5ad2 into facebook:master Oct 16, 2020
@gaearon gaearon deleted the rm-dead branch October 16, 2020 15:49
koto pushed a commit to koto/react that referenced this pull request Jun 15, 2021
* Remove dead code branch

This function is only called when initializing roots/containers (where we skip non-delegated events) and in the createEventHandle path for non-DOM nodes (where we never hit this path because targetElement is null).

* Move related functions close to each other

* Fork listenToNativeEvent for createEventHandle

It doesn't need all of the logic that's needed for normal event path.

And the normal codepath doesn't use the last two arguments.

* Expand test coverage for non-delegated events

This changes a test to fail if we removed the event handler Sets. Previously, we didn't cover that.

* Add DEV-level check that top-level events and non-delegated events do not overlap

This makes us confident that they're mutually exclusive and there is no duplication between them.

* Add a test verifying selectionchange deduplication

This is why we still need the Set bookkeeping. Adding a test for it.

* Remove Set bookkeeping for root events

Root events don't intersect with non-delegated bubbled events (so no need to deduplicate there). They also don't intersect with createEventHandle non-managed events (because those don't go on the DOM elements). So we can remove the bookeeping because we already have code ensuring the eager subscriptions only run once per element.

I've moved the selectionchange special case outside, and added document-level deduplication for it alone.

Technically this might change the behavior of createEventHandle with selectionchange on the document, but we're not using that, and I'm not sure that behavior makes sense anyway.

* Flow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants