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

Remove event pooling in the modern system #18216

Closed
wants to merge 1 commit into from

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Mar 5, 2020

This is a proposal.

Event pooling saves allocations during high firing events, but adds a bit overhead in "releasing", "destroying" and "reusing" instances. I'm not sure this is actually beneficial. Nobody else is doing it so it's not like this is a common practice. I think maybe we can experiment with dropping it altogether. We didn't do this before because it's technically a breaking change, but since we're changing a bunch of things about events anyway, maybe we can sneak it in? It's less of a chance than the move to roots, for example.

Pooling is confusing. For example, not being to access e.target in the setState updater has been a pain. Although maybe reading that early is best practice so you capture the right value etc. But the way it currently fails is very unintuitive. So maybe it's worth fixing even if we add a lint warning against that. I think the conceptual simplicity win is still valuable.

Effectively this moves all pooling related code behind a flag. I kept getPooled because it's scattered across the codebase, but in modern mode this just calls the constructor immediately. I also kept the public API, but persist is a no-op and isPersistent always returns true in modern mode.

@gaearon gaearon requested a review from trueadm March 5, 2020 01:22
@facebook-github-bot facebook-github-bot added the React Core Team Opened by a member of the React Core Team label Mar 5, 2020
@gaearon gaearon requested a review from sebmarkbage March 5, 2020 01:22
const Interface = this.constructor.Interface;
for (const propName in Interface) {
// Modern event system doesn't use pooling.
if (!enableModernEventSystem) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 5, 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 029f99a:

Sandbox Source
focused-sky-ov8pr Configuration

@sizebot
Copy link

sizebot commented Mar 5, 2020

Details of bundled changes.

Comparing: 2fe0fbb...029f99a

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js 0.0% 0.0% 123.82 KB 123.82 KB 38.64 KB 38.64 KB NODE_PROFILING
react-dom-unstable-native-dependencies.development.js +0.9% +0.5% 58.91 KB 59.42 KB 14.71 KB 14.78 KB UMD_DEV
ReactDOM-dev.js +0.1% 0.0% 897.13 KB 897.63 KB 200.49 KB 200.58 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 10.27 KB 10.27 KB 3.49 KB 3.5 KB UMD_PROD
ReactDOMServer-dev.js 0.0% 0.0% 136.85 KB 136.85 KB 34.94 KB 34.94 KB FB_WWW_DEV
react-dom-test-utils.development.js +0.7% +0.4% 53.78 KB 54.17 KB 14.01 KB 14.07 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% 🔺+0.1% 10.96 KB 10.96 KB 4.17 KB 4.17 KB UMD_PROD
ReactDOMTesting-dev.js +0.1% 0.0% 872.36 KB 872.86 KB 195.35 KB 195.44 KB FB_WWW_DEV
ReactDOMTesting-prod.js 0.0% 0.0% 368.7 KB 368.73 KB 67.45 KB 67.46 KB FB_WWW_PROD
react-dom-test-utils.development.js +0.7% +0.5% 49.56 KB 49.92 KB 13.52 KB 13.59 KB NODE_DEV
ReactDOMTesting-profiling.js 0.0% 0.0% 368.7 KB 368.73 KB 67.45 KB 67.46 KB FB_WWW_PROFILING
react-dom-server.node.development.js 0.0% 0.0% 130.6 KB 130.6 KB 34.69 KB 34.69 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% 🔺+0.1% 10.81 KB 10.81 KB 4.1 KB 4.1 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% 0.0% 20.82 KB 20.82 KB 7.6 KB 7.6 KB NODE_PROD
react-dom.development.js 0.0% 0.0% 912.43 KB 912.88 KB 199.6 KB 199.7 KB UMD_DEV
react-dom-server.browser.development.js 0.0% 0.0% 136.37 KB 136.37 KB 34.84 KB 34.84 KB UMD_DEV
react-dom.production.min.js 0.0% 0.0% 119.87 KB 119.87 KB 38.29 KB 38.29 KB UMD_PROD
ReactTestUtils-dev.js +0.9% +0.4% 51.31 KB 51.76 KB 13.7 KB 13.76 KB FB_WWW_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 20.49 KB 20.49 KB 7.5 KB 7.5 KB UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 123.52 KB 123.52 KB 39.44 KB 39.45 KB UMD_PROFILING
react-dom.development.js 0.0% 0.0% 868.51 KB 868.93 KB 197.21 KB 197.29 KB NODE_DEV
react-dom-server.browser.development.js 0.0% 0.0% 129.38 KB 129.38 KB 34.43 KB 34.43 KB NODE_DEV
react-dom.production.min.js 0.0% 0.0% 120.02 KB 120.02 KB 37.52 KB 37.52 KB NODE_PROD
react-dom-server.browser.production.min.js 0.0% 0.0% 20.41 KB 20.41 KB 7.45 KB 7.45 KB NODE_PROD
ReactDOM-prod.js 0.0% 0.0% 370.67 KB 370.7 KB 67.55 KB 67.56 KB FB_WWW_PROD
ReactDOM-profiling.js 0.0% 0.0% 381.94 KB 381.96 KB 69.66 KB 69.67 KB FB_WWW_PROFILING
react-dom-unstable-native-dependencies.development.js +0.9% +0.6% 55.87 KB 56.35 KB 14.47 KB 14.56 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 3.69 KB 3.69 KB 1.34 KB 1.34 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 10 KB 10 KB 3.37 KB 3.37 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.3% 1.16 KB 1.16 KB 661 B 663 B NODE_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.1% 1.19 KB 1.19 KB 698 B 699 B UMD_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 2.95 KB 2.95 KB 1.18 KB 1.18 KB NODE_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.2% 1 KB 1 KB 609 B 610 B NODE_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-prod.js 0.0% 0.0% 259.77 KB 259.79 KB 45.2 KB 45.2 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js 0.0% 0.0% 271.1 KB 271.13 KB 47.34 KB 47.35 KB RN_OSS_PROFILING
ReactFabric-prod.js 0.0% 0.0% 251.73 KB 251.76 KB 43.71 KB 43.71 KB RN_OSS_PROD
ReactFabric-profiling.js 0.0% 0.0% 263.07 KB 263.09 KB 45.88 KB 45.89 KB RN_OSS_PROFILING
ReactFabric-dev.js +0.1% +0.1% 616.94 KB 617.56 KB 133.08 KB 133.17 KB RN_FB_DEV
ReactFabric-prod.js 0.0% 0.0% 251.88 KB 251.91 KB 43.74 KB 43.75 KB RN_FB_PROD
ReactNativeRenderer-dev.js +0.1% 0.0% 632.2 KB 632.82 KB 137.03 KB 137.09 KB RN_OSS_DEV
ReactFabric-profiling.js 0.0% 0.0% 263.21 KB 263.24 KB 45.93 KB 45.93 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js +0.1% 0.0% 634.83 KB 635.45 KB 137.37 KB 137.43 KB RN_FB_DEV
ReactNativeRenderer-prod.js 0.0% 0.0% 259.91 KB 259.94 KB 45.22 KB 45.23 KB RN_FB_PROD
ReactNativeRenderer-profiling.js 0.0% 0.0% 271.24 KB 271.27 KB 47.39 KB 47.4 KB RN_FB_PROFILING
ReactFabric-dev.js +0.1% +0.1% 614.3 KB 614.92 KB 132.75 KB 132.84 KB RN_OSS_DEV

ReactDOM: size: 0.0%, gzip: 0.0%

Size changes (experimental)

Generated by 🚫 dangerJS against 029f99a

@sizebot
Copy link

sizebot commented Mar 5, 2020

Details of bundled changes.

Comparing: 2fe0fbb...029f99a

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactFabric-dev.js +0.1% +0.1% 614.29 KB 614.91 KB 132.75 KB 132.83 KB RN_OSS_DEV
ReactNativeRenderer-dev.js +0.1% 0.0% 632.19 KB 632.81 KB 137.02 KB 137.08 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 0.0% 0.0% 259.75 KB 259.78 KB 45.19 KB 45.19 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js 0.0% 0.0% 271.09 KB 271.12 KB 47.33 KB 47.34 KB RN_OSS_PROFILING
ReactFabric-prod.js 0.0% 0.0% 251.72 KB 251.74 KB 43.7 KB 43.71 KB RN_OSS_PROD
ReactFabric-profiling.js 0.0% 0.0% 263.05 KB 263.08 KB 45.87 KB 45.88 KB RN_OSS_PROFILING

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactDOM-profiling.js 0.0% 0.0% 406.33 KB 406.36 KB 74.07 KB 74.08 KB FB_WWW_PROFILING
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.2% 1.15 KB 1.15 KB 653 B 654 B NODE_PROD
react-dom-server.browser.production.min.js 0.0% 0.0% 20.03 KB 20.03 KB 7.41 KB 7.41 KB UMD_PROD
ReactTestUtils-dev.js +0.9% +0.4% 51.31 KB 51.76 KB 13.7 KB 13.75 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.development.js +0.9% +0.6% 55.86 KB 56.34 KB 14.46 KB 14.55 KB NODE_DEV
react-dom.development.js +0.1% 0.0% 883.74 KB 884.2 KB 194.69 KB 194.78 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 9.99 KB 9.99 KB 3.36 KB 3.37 KB NODE_PROD
react-dom.production.min.js 0.0% 0.0% 116 KB 116 KB 37.14 KB 37.14 KB UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 119.53 KB 119.53 KB 38.34 KB 38.34 KB UMD_PROFILING
react-dom.development.js +0.1% 0.0% 841.01 KB 841.44 KB 192.31 KB 192.4 KB NODE_DEV
react-dom-server.node.development.js 0.0% 0.0% 129.09 KB 129.09 KB 34.47 KB 34.47 KB NODE_DEV
react-dom.production.min.js 0.0% 0.0% 116.08 KB 116.08 KB 36.5 KB 36.5 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% 0.0% 20.36 KB 20.36 KB 7.52 KB 7.52 KB NODE_PROD
react-dom.profiling.min.js 0.0% 0.0% 119.76 KB 119.76 KB 37.58 KB 37.58 KB NODE_PROFILING
ReactDOM-dev.js +0.1% 0.0% 939.37 KB 939.88 KB 209.37 KB 209.47 KB FB_WWW_DEV
ReactDOM-prod.js 0.0% 0.0% 395 KB 395.02 KB 71.89 KB 71.9 KB FB_WWW_PROD
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 3.68 KB 3.68 KB 1.33 KB 1.33 KB NODE_DEV
ReactDOMTesting-dev.js +0.1% +0.1% 899 KB 899.51 KB 200.88 KB 200.99 KB FB_WWW_DEV
ReactDOMTesting-prod.js 0.0% 0.0% 382.25 KB 382.27 KB 69.63 KB 69.63 KB FB_WWW_PROD
react-dom-test-utils.development.js +0.7% +0.4% 53.77 KB 54.15 KB 14 KB 14.06 KB UMD_DEV
ReactDOMTesting-profiling.js 0.0% 0.0% 382.25 KB 382.27 KB 69.63 KB 69.63 KB FB_WWW_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 19.95 KB 19.95 KB 7.37 KB 7.37 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.34 KB 3.34 KB 1.26 KB 1.26 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% 🔺+0.1% 10.94 KB 10.94 KB 4.16 KB 4.16 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.1% 1.17 KB 1.17 KB 690 B 691 B UMD_PROD
ReactDOMServer-dev.js 0.0% 0.0% 137.7 KB 137.7 KB 35.08 KB 35.08 KB FB_WWW_DEV
react-dom-test-utils.development.js +0.7% +0.5% 49.55 KB 49.91 KB 13.51 KB 13.58 KB NODE_DEV
ReactDOMServer-prod.js 0.0% 0.0% 47.45 KB 47.45 KB 11.04 KB 11.04 KB FB_WWW_PROD
react-dom-test-utils.production.min.js 0.0% 🔺+0.1% 10.79 KB 10.79 KB 4.09 KB 4.09 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js +0.9% +0.5% 58.9 KB 59.41 KB 14.7 KB 14.78 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.2% 1013 B 1013 B 601 B 602 B NODE_PROD
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.26 KB 10.26 KB 3.49 KB 3.49 KB UMD_PROD

ReactDOM: size: 0.0%, gzip: 0.0%

Size changes (stable)

Generated by 🚫 dangerJS against 029f99a

@sebmarkbage
Copy link
Collaborator

sebmarkbage commented Mar 5, 2020

but since we're changing a bunch of things about events anyway, maybe we can sneak it in?

This is the wrong intuition and I think we should probably wait. There are a ton of things that we should be doing that we're not doing and we really need to hold the line hard. If we were to introduce breaking changes there are a number of other that would be higher pri than this.

Any small breaking change adds to the risk that people can't upgrade to the next major. If they can't upgrade to the next major they can't isolate a small subsection of their site. If they can't do that, they won't be able to adopt the next major after that at all.

All the breaking changes in the next major should only be in service of unlocking the ability to pin a subtree to an old version which is the point of the "modern system". I'd even go as far as saying we shouldn't enable new warnings in 17.0. Only in a future minor.

@sebmarkbage
Copy link
Collaborator

Behind a different flag that we can do it next one would be make sense though.

@@ -152,71 +154,79 @@ Object.assign(SyntheticEvent.prototype, {
* won't be added back into the pool.
*/
persist: function() {
this.isPersistent = functionThatReturnsTrue;
// Modern event system doesn't use pooling.
if (!enableModernEventSystem) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We'd probably want to add a warning on using persist(), as it'll just be dead code in apps otherwise.

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

You'll need to address Seb's request to put it behind another flag, however the implementation looks good otherwise. If you do put it behind another flag, don't forget to add the release() bit back into the modern event system module again.

@philipp-spiess
Copy link
Contributor

I wonder if we can go further and remove the heavy synthetic event system that requires all property names to be hardcoded so we can copy them to a small object that only sets the target and prototype links to the nativeEvent?

@gaearon
Copy link
Collaborator Author

gaearon commented Mar 5, 2020

@philipp-spiess This part of Seb's comment probably applies here:

There are a ton of things that we should be doing that we're not doing and we really need to hold the line hard. If we were to introduce breaking changes there are a number of other that would be higher pri than this.

@trueadm
Copy link
Contributor

trueadm commented May 21, 2020

I made a follow up to this PR in #18969.

@trueadm trueadm closed this May 21, 2020
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.

6 participants