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

Separate SyntheticEvent constructors to prevent deopts #19907

Merged
merged 3 commits into from Sep 25, 2020

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Sep 25, 2020

Builds on #19906. (Well, really, replaces it.)

I suspect that I introduced a regression way back in #19433 when I removed the SyntheticEvent.extend helper. I'm not 100% sure but I think that as a result of going through different Interfaces in the same function instance, the single SyntheticEvent constructor has become megamorphic (because we'd set different fields in different order on this). It is a very hot path (and even more so with the eager change) so I'm splitting these into separate function instances.

With this change, I'm consistently seeing ~20% less time spent inside the constructor on average.

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Sep 25, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 25, 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 22cd1e5:

Sandbox Source
React Configuration

@sizebot
Copy link

sizebot commented Sep 25, 2020

Details of bundled changes.

Comparing: c91c1c4...22cd1e5

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.1% +0.1% 908.28 KB 909.52 KB 206.39 KB 206.62 KB NODE_DEV
ReactDOMForked-prod.js 🔺+0.3% 🔺+0.2% 375.79 KB 376.82 KB 69.69 KB 69.84 KB FB_WWW_PROD
react-dom.production.min.js 🔺+0.1% 🔺+0.2% 122.28 KB 122.35 KB 39.34 KB 39.4 KB NODE_PROD
ReactDOMForked-profiling.js +0.3% +0.2% 389.26 KB 390.29 KB 72.1 KB 72.24 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.4% 🔺+0.2% 13.66 KB 13.71 KB 5.31 KB 5.32 KB UMD_PROD
ReactDOMTesting-dev.js +0.1% +0.1% 912.12 KB 913.33 KB 205.29 KB 205.5 KB FB_WWW_DEV
react-dom-test-utils.development.js +1.9% +1.2% 65.06 KB 66.29 KB 18.63 KB 18.84 KB NODE_DEV
ReactDOMTesting-prod.js 🔺+0.3% 🔺+0.2% 371.99 KB 373.02 KB 70.21 KB 70.38 KB FB_WWW_PROD
react-dom-test-utils.production.min.js 🔺+0.8% 🔺+0.8% 13.59 KB 13.7 KB 5.22 KB 5.27 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.2% 1.17 KB 1.17 KB 666 B 667 B NODE_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.1% 1.22 KB 1.22 KB 711 B 712 B UMD_PROD
ReactTestUtils-dev.js +2.0% +1.4% 59.7 KB 60.92 KB 16.56 KB 16.79 KB FB_WWW_DEV
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 4.78 KB 4.78 KB 1.68 KB 1.68 KB NODE_DEV
react-dom.development.js +0.1% +0.1% 954.43 KB 955.71 KB 209 KB 209.21 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.0% 0.0% 122.11 KB 122.17 KB 40.09 KB 40.1 KB UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 127.36 KB 127.43 KB 41.76 KB 41.76 KB UMD_PROFILING
ReactDOMForked-dev.js +0.1% +0.1% 962.75 KB 963.97 KB 214.25 KB 214.46 KB FB_WWW_DEV
react-dom.profiling.min.js 0.0% +0.1% 127.72 KB 127.78 KB 41.01 KB 41.06 KB NODE_PROFILING
ReactDOM-dev.js +0.1% +0.1% 961.26 KB 962.47 KB 214.66 KB 214.86 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.3% 🔺+0.2% 374.58 KB 375.61 KB 69.39 KB 69.53 KB FB_WWW_PROD
ReactDOM-profiling.js +0.3% +0.2% 387.74 KB 388.77 KB 71.82 KB 71.96 KB FB_WWW_PROFILING
react-dom-test-utils.development.js +1.8% +1.3% 70.22 KB 71.48 KB 19.12 KB 19.36 KB UMD_DEV

ReactDOM: size: 🔺+0.4%, gzip: 🔺+0.2%

Size changes (experimental)

Generated by 🚫 dangerJS against 22cd1e5

@sizebot
Copy link

sizebot commented Sep 25, 2020

Details of bundled changes.

Comparing: c91c1c4...22cd1e5

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.1% +0.1% 872.83 KB 874.07 KB 199.89 KB 200.1 KB NODE_DEV
ReactDOMForked-prod.js 🔺+0.3% 🔺+0.2% 387.12 KB 388.15 KB 71.45 KB 71.59 KB FB_WWW_PROD
react-dom.production.min.js 🔺+0.1% 🔺+0.2% 117.72 KB 117.78 KB 38.02 KB 38.09 KB NODE_PROD
ReactDOMForked-profiling.js +0.3% +0.2% 400.64 KB 401.67 KB 73.83 KB 73.97 KB FB_WWW_PROFILING
react-dom-test-utils.production.min.js 🔺+0.4% 🔺+0.1% 13.65 KB 13.7 KB 5.31 KB 5.31 KB UMD_PROD
ReactDOMTesting-dev.js +0.1% +0.1% 940.45 KB 941.67 KB 210.76 KB 210.97 KB FB_WWW_DEV
react-dom-test-utils.development.js +1.9% +1.2% 65.05 KB 66.28 KB 18.62 KB 18.84 KB NODE_DEV
ReactDOMTesting-prod.js 🔺+0.3% 🔺+0.2% 385.05 KB 386.08 KB 72.38 KB 72.5 KB FB_WWW_PROD
react-dom-test-utils.production.min.js 🔺+0.8% 🔺+0.8% 13.58 KB 13.68 KB 5.21 KB 5.26 KB NODE_PROD
ReactTestUtils-dev.js +2.0% +1.4% 59.7 KB 60.92 KB 16.56 KB 16.78 KB FB_WWW_DEV
react-dom.development.js +0.1% +0.1% 917.24 KB 918.51 KB 202.43 KB 202.65 KB UMD_DEV
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 117.62 KB 117.68 KB 38.71 KB 38.75 KB UMD_PROD
react-dom.profiling.min.js +0.1% +0.1% 121.51 KB 121.57 KB 39.92 KB 39.95 KB UMD_PROFILING
ReactDOMForked-dev.js +0.1% +0.1% 988.34 KB 989.55 KB 218.96 KB 219.18 KB FB_WWW_DEV
react-dom.profiling.min.js +0.1% +0.2% 121.79 KB 121.85 KB 39.22 KB 39.28 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.1% +0.1% 986.84 KB 988.05 KB 219.32 KB 219.53 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.3% 🔺+0.2% 385.83 KB 386.86 KB 71.1 KB 71.23 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.3% +0.2% 399.04 KB 400.07 KB 73.53 KB 73.66 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
react-dom-test-utils.development.js +1.8% +1.3% 70.21 KB 71.47 KB 19.11 KB 19.35 KB UMD_DEV

ReactDOM: size: 🔺+0.4%, gzip: 🔺+0.1%

Size changes (stable)

Generated by 🚫 dangerJS against 22cd1e5

@gaearon
Copy link
Collaborator Author

gaearon commented Sep 25, 2020

Debugging the Flow fix is gonna be fun given Flow is broken for me locally. Sigh.

@gaearon gaearon merged commit 1890159 into facebook:master Sep 25, 2020
koto pushed a commit to koto/react that referenced this pull request Jun 15, 2021
* Remove arguments from hot path

* Make SyntheticEvent subtypes monomorphic

* Maybe fix 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.

None yet

4 participants