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

Refactor ElementListenerMap to use expando properties #18766

Merged
merged 1 commit into from
Apr 28, 2020

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Apr 28, 2020

Note: Last year, I originally made the change that moved this code to use WeakMaps in #15036.

I recently did some profiling and noticed that we are spending quite a bit of time accessing and setting Maps on DOMEventListenerMap's WeakMap for each element when using the Modern Event System. The times weren't huge, they were just collectively many more ms than I would have liked. I profiled switching back to a Map and the times do go down, but then we end up likely leaking by making that change. Why didn't we notice this before? Well I believe it has to do with the fact that we almost always were doing lookups on the document as the WeakMap key, with very few other DOM nodes used as keys. Doing expando lookups on document is about equivalent in performance to doing lookups with a WeakMap (document has only a slow path?). Now that we've moved to roots, I'm now seeing a more noticeable perf difference.

With all that in mind, I've moved us back to using internal expando properties on DOM nodes instead, which fixes the performance issue I was seeing. I also don't see any regressions with the legacy event system doing this.

@trueadm trueadm requested review from sebmarkbage and gaearon April 28, 2020 11:05
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Apr 28, 2020
@trueadm trueadm changed the title Refactor ElementListenerMap Refactor ElementListenerMap to use expando properties Apr 28, 2020
@trueadm trueadm force-pushed the refactor-element-listener-map branch 2 times, most recently from 133a687 to 94232f5 Compare April 28, 2020 11:12
@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 28, 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 ad834b1:

Sandbox Source
cool-rhodes-x36lt Configuration

@sizebot
Copy link

sizebot commented Apr 28, 2020

Details of bundled changes.

Comparing: 4b02b66...ad834b1

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% 128.73 KB 128.69 KB 40.29 KB 40.27 KB NODE_PROFILING
ReactDOM-dev.js -0.0% 0.0% 1012.39 KB 1012.38 KB 225.59 KB 225.64 KB FB_WWW_DEV
ReactDOMServer-dev.js 0.0% -0.0% 160.18 KB 160.18 KB 40.81 KB 40.81 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.1% 0.0% 420.21 KB 420.67 KB 73.78 KB 73.79 KB FB_WWW_PROD
ReactDOMServer-prod.js 0.0% -0.0% 52.03 KB 52.03 KB 12.54 KB 12.53 KB FB_WWW_PROD
ReactDOM-profiling.js +0.1% 0.0% 431.11 KB 431.57 KB 75.62 KB 75.64 KB FB_WWW_PROFILING
react-dom-unstable-fizz.node.development.js 0.0% -0.1% 5.42 KB 5.42 KB 1.81 KB 1.81 KB NODE_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% -0.3% 1.17 KB 1.17 KB 668 B 666 B NODE_PROD
react-dom-test-utils.development.js 0.0% -0.0% 75.14 KB 75.14 KB 20.13 KB 20.13 KB UMD_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 5.17 KB 5.17 KB 1.75 KB 1.75 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 13.24 KB 13.24 KB 4.9 KB 4.9 KB UMD_PROD
ReactDOMTesting-dev.js -0.0% -0.0% 908.54 KB 908.3 KB 202.76 KB 202.75 KB FB_WWW_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.1% 1.2 KB 1.2 KB 706 B 705 B UMD_PROD
ReactDOMTesting-prod.js -0.0% -0.1% 378.11 KB 378.04 KB 69.1 KB 69.06 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% -0.0% 69.98 KB 69.98 KB 19.63 KB 19.63 KB NODE_DEV
ReactDOMTesting-profiling.js -0.0% -0.1% 378.11 KB 378.04 KB 69.1 KB 69.06 KB FB_WWW_PROFILING
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 4.68 KB 4.68 KB 1.65 KB 1.65 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 13.12 KB 13.12 KB 4.81 KB 4.81 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% -0.0% 23.7 KB 23.7 KB 8.74 KB 8.74 KB NODE_PROD
react-dom.development.js -0.0% -0.0% 940.55 KB 940.3 KB 205.79 KB 205.75 KB UMD_DEV
react-dom.production.min.js -0.0% -0.1% 124.53 KB 124.5 KB 39.9 KB 39.87 KB UMD_PROD
ReactDOMForked-dev.js -0.0% 0.0% 1004.41 KB 1004.4 KB 224.31 KB 224.38 KB FB_WWW_DEV
react-dom.profiling.min.js -0.0% -0.0% 128.39 KB 128.35 KB 41.04 KB 41.02 KB UMD_PROFILING
ReactDOMForked-prod.js 🔺+0.1% 0.0% 420.78 KB 421.24 KB 73.86 KB 73.86 KB FB_WWW_PROD
react-dom.development.js -0.0% -0.0% 895.45 KB 895.22 KB 203.27 KB 203.22 KB NODE_DEV
ReactDOMForked-profiling.js +0.1% 0.0% 431.68 KB 432.14 KB 75.71 KB 75.73 KB FB_WWW_PROFILING
react-dom.production.min.js -0.0% -0.1% 124.73 KB 124.69 KB 39.02 KB 38.99 KB NODE_PROD
react-dom-server.browser.production.min.js 0.0% -0.0% 23.29 KB 23.29 KB 8.59 KB 8.59 KB NODE_PROD

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

Size changes (experimental)

Generated by 🚫 dangerJS against ad834b1

@sizebot
Copy link

sizebot commented Apr 28, 2020

Details of bundled changes.

Comparing: 4b02b66...ad834b1

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.production.min.js -0.0% -0.0% 119.82 KB 119.78 KB 37.6 KB 37.6 KB NODE_PROD
react-dom-test-utils.development.js 0.0% -0.0% 75.13 KB 75.13 KB 20.13 KB 20.13 KB UMD_DEV
ReactDOMTesting-profiling.js -0.0% -0.0% 389.97 KB 389.89 KB 71.09 KB 71.07 KB FB_WWW_PROFILING
react-dom-server.node.production.min.js 0.0% -0.0% 23.24 KB 23.24 KB 8.66 KB 8.65 KB NODE_PROD
react-dom.profiling.min.js -0.0% -0.1% 123.7 KB 123.66 KB 38.77 KB 38.75 KB NODE_PROFILING
ReactDOMServer-prod.js 0.0% -0.0% 52.92 KB 52.92 KB 12.72 KB 12.72 KB FB_WWW_PROD
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 4.67 KB 4.67 KB 1.64 KB 1.64 KB NODE_DEV
ReactDOMForked-dev.js -0.0% -0.0% 1.01 MB 1.01 MB 229.97 KB 229.91 KB FB_WWW_DEV
ReactDOMForked-prod.js 🔺+0.1% 0.0% 432.26 KB 432.72 KB 75.86 KB 75.87 KB FB_WWW_PROD
react-dom.development.js -0.0% -0.0% 906.66 KB 906.42 KB 199.32 KB 199.28 KB UMD_DEV
ReactDOMForked-profiling.js +0.1% 0.0% 443.22 KB 443.68 KB 77.73 KB 77.75 KB FB_WWW_PROFILING
react-dom.production.min.js -0.0% 0.0% 119.69 KB 119.66 KB 38.37 KB 38.37 KB UMD_PROD
react-dom.profiling.min.js -0.0% -0.1% 123.44 KB 123.41 KB 39.59 KB 39.56 KB UMD_PROFILING
ReactDOMTesting-dev.js -0.0% -0.1% 934.33 KB 934.09 KB 208.39 KB 208.28 KB FB_WWW_DEV
react-dom.development.js -0.0% -0.0% 863.02 KB 862.78 KB 196.79 KB 196.75 KB NODE_DEV
ReactDOMTesting-prod.js -0.0% -0.0% 389.97 KB 389.89 KB 71.09 KB 71.07 KB FB_WWW_PROD
ReactDOM-dev.js -0.0% -0.0% 1.01 MB 1.01 MB 231.25 KB 231.19 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.1% 0.0% 431.68 KB 432.14 KB 75.77 KB 75.78 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% -0.0% 69.97 KB 69.97 KB 19.62 KB 19.62 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% -0.1% 5.41 KB 5.41 KB 1.8 KB 1.8 KB NODE_DEV
ReactDOM-profiling.js +0.1% 0.0% 442.64 KB 443.09 KB 77.66 KB 77.67 KB FB_WWW_PROFILING
react-dom-test-utils.production.min.js 0.0% 0.0% 13.1 KB 13.1 KB 4.8 KB 4.8 KB NODE_PROD
react-dom-server.browser.development.js 0.0% 0.0% 154.77 KB 154.77 KB 39.44 KB 39.44 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% -0.2% 1.16 KB 1.16 KB 660 B 659 B NODE_PROD
react-dom-server.browser.production.min.js 0.0% -0.0% 22.94 KB 22.94 KB 8.52 KB 8.52 KB UMD_PROD
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 5.15 KB 5.15 KB 1.74 KB 1.74 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.1% 1.19 KB 1.19 KB 698 B 697 B UMD_PROD

Size changes (stable)

Generated by 🚫 dangerJS against ad834b1

Cleanup

Cleanup

Address comments
@trueadm trueadm force-pushed the refactor-element-listener-map branch from 94232f5 to ad834b1 Compare April 28, 2020 20:08
@trueadm trueadm merged commit 88d0be6 into facebook:master Apr 28, 2020
@trueadm trueadm deleted the refactor-element-listener-map branch April 28, 2020 20:53
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.

5 participants