Skip to content

[react-dom] Refactor event priority handling to its own module#17678

Merged
trueadm merged 1 commit intofacebook:masterfrom
trueadm:event-priority-refactor
Dec 20, 2019
Merged

[react-dom] Refactor event priority handling to its own module#17678
trueadm merged 1 commit intofacebook:masterfrom
trueadm:event-priority-refactor

Conversation

@trueadm
Copy link
Contributor

@trueadm trueadm commented Dec 20, 2019

The team have mentioned a bunch of times that it felt wrong that DOM Event Priority handling was all coupled with the SimpleEventPlugin, especially as might want to extend on the priorities with newer features and refactors in the future.

This PR breaks out the priority logic into a dedicated module and makes uses of Maps for faster lookups (I benchmarked before and after and Maps were consistently faster than object property lookups in Chrome and Safari, neutral in Firefox). We should also get a slight code size saving by some of the code golfing that I did whilst refactoring the code.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 20, 2019

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 bf1ed10:

Sandbox Source
pedantic-feistel-ou1ly Configuration

@sizebot
Copy link

sizebot commented Dec 20, 2019

Details of bundled changes.

Comparing: dbc46ac...bf1ed10

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js -0.4% -0.4% 123.65 KB 123.16 KB 38.89 KB 38.74 KB NODE_PROFILING
react-dom-server.browser.development.js 0.0% -0.0% 137.71 KB 137.71 KB 36.61 KB 36.61 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 20.45 KB 20.45 KB 7.5 KB 7.5 KB UMD_PROD
react-dom-test-utils.development.js 0.0% -0.0% 54.5 KB 54.5 KB 15.32 KB 15.31 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% -0.1% 11.18 KB 11.18 KB 4.15 KB 4.15 KB UMD_PROD
react-dom-test-utils.development.js 0.0% -0.0% 52.77 KB 52.77 KB 14.99 KB 14.99 KB NODE_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.71 KB 3.71 KB 1.5 KB 1.5 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.1% 10.95 KB 10.95 KB 4.09 KB 4.09 KB NODE_PROD
react-dom.development.js -0.0% -0.1% 951.51 KB 951.36 KB 215.42 KB 215.15 KB UMD_DEV
react-dom.production.min.js -0.4% -0.5% 119.68 KB 119.19 KB 38.5 KB 38.29 KB UMD_PROD
react-dom.profiling.min.js -0.4% -0.4% 123.42 KB 122.93 KB 39.66 KB 39.52 KB UMD_PROFILING
react-dom.development.js -0.0% -0.1% 945.58 KB 945.43 KB 213.77 KB 213.48 KB NODE_DEV
react-dom.production.min.js -0.4% -0.4% 119.77 KB 119.28 KB 37.76 KB 37.61 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% -0.0% 20.79 KB 20.79 KB 7.63 KB 7.62 KB NODE_PROD
ReactDOM-dev.js -0.0% -0.1% 973.5 KB 973.3 KB 216.64 KB 216.45 KB FB_WWW_DEV
ReactDOM-prod.js -0.1% -0.2% 394.64 KB 394.15 KB 72.3 KB 72.19 KB FB_WWW_PROD
ReactDOM-profiling.js -0.1% -0.1% 405.94 KB 405.44 KB 74.42 KB 74.35 KB FB_WWW_PROFILING
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.1% 10.23 KB 10.23 KB 3.47 KB 3.47 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.61 KB 60.61 KB 15.99 KB 15.99 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% -0.1% 4.42 KB 4.42 KB 1.65 KB 1.65 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 9.97 KB 9.97 KB 3.37 KB 3.37 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% -0.1% 1.21 KB 1.21 KB 697 B 696 B NODE_PROD

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

Size changes (experimental)

Generated by 🚫 dangerJS against bf1ed10

Copy link
Contributor

@philipp-spiess philipp-spiess left a comment

Choose a reason for hiding this comment

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

👀

@sizebot
Copy link

sizebot commented Dec 20, 2019

Details of bundled changes.

Comparing: dbc46ac...bf1ed10

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom-server.browser.production.min.js 0.0% -0.0% 19.92 KB 19.92 KB 7.39 KB 7.39 KB NODE_PROD
react-dom-test-utils.development.js 0.0% -0.0% 52.76 KB 52.76 KB 14.99 KB 14.99 KB NODE_DEV
react-dom.production.min.js -0.4% -0.6% 115.84 KB 115.35 KB 37.38 KB 37.17 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.59 KB 60.59 KB 15.99 KB 15.99 KB NODE_DEV
react-dom.profiling.min.js -0.4% -0.4% 119.47 KB 118.98 KB 38.53 KB 38.36 KB UMD_PROFILING
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 9.96 KB 9.96 KB 3.36 KB 3.36 KB NODE_PROD
react-dom.development.js -0.0% -0.1% 945.56 KB 945.41 KB 213.74 KB 213.45 KB NODE_DEV
react-dom.production.min.js -0.4% -0.4% 115.9 KB 115.42 KB 36.69 KB 36.53 KB NODE_PROD
react-dom.profiling.min.js -0.4% -0.5% 119.67 KB 119.18 KB 37.83 KB 37.65 KB NODE_PROFILING
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.87 KB 3.87 KB 1.54 KB 1.54 KB UMD_DEV
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.7 KB 3.7 KB 1.49 KB 1.49 KB NODE_DEV
react-dom-test-utils.development.js 0.0% -0.0% 54.48 KB 54.48 KB 15.31 KB 15.31 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% -0.1% 11.17 KB 11.17 KB 4.14 KB 4.14 KB UMD_PROD
react-dom-test-utils.production.min.js 0.0% -0.1% 10.94 KB 10.94 KB 4.08 KB 4.08 KB NODE_PROD
react-dom-unstable-fizz.node.development.js 0.0% -0.1% 4.4 KB 4.4 KB 1.64 KB 1.64 KB NODE_DEV
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.89 KB 60.89 KB 16.06 KB 16.06 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.22 KB 10.22 KB 3.47 KB 3.46 KB UMD_PROD
react-dom.development.js -0.0% -0.1% 951.49 KB 951.34 KB 215.4 KB 215.13 KB UMD_DEV

ReactDOM: size: -0.4%, gzip: -0.6%

Size changes (stable)

Generated by 🚫 dangerJS against bf1ed10

@trueadm trueadm force-pushed the event-priority-refactor branch from 2f6b4be to 5ef8236 Compare December 20, 2019 15:11
@trueadm trueadm force-pushed the event-priority-refactor branch 2 times, most recently from 7059476 to 5c4998d Compare December 20, 2019 16:15
@trueadm
Copy link
Contributor Author

trueadm commented Dec 20, 2019

I did some benchmarking on FF and Safari and it looks like using multiple Sets is not as optimal as Chrome's V8. I've changed my approach to use Maps and moved things around so we don't do multiple lookups – this is now consistently faster in Chrome and Safari, neutral in Firefox. I also did some neat code golfing to save us more code size compared to master!

@trueadm trueadm force-pushed the event-priority-refactor branch 2 times, most recently from c292316 to e12b4bf Compare December 20, 2019 19:38
Copy link
Contributor

@necolas necolas left a comment

Choose a reason for hiding this comment

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

Can we avoid creating the cyclic dependency?

priority: EventPriority,
): void {
// As the event types are in pairs of two, we need to iterate
// through in twos.
Copy link
Contributor

Choose a reason for hiding this comment

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

😮 neat!

Copy link
Contributor

Choose a reason for hiding this comment

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

eek though

@trueadm trueadm force-pushed the event-priority-refactor branch 3 times, most recently from f6634dc to 0df550e Compare December 20, 2019 19:50
Fix lint

Revise comment

Revise strategy

Did some code golfing

Added comment about iteration

Remove cyclic dependency

Fix typo

Extend comment

Fix typo
@trueadm trueadm force-pushed the event-priority-refactor branch from 0df550e to bf1ed10 Compare December 20, 2019 19:53
@trueadm trueadm merged commit 85d9655 into facebook:master Dec 20, 2019
@trueadm trueadm deleted the event-priority-refactor branch December 20, 2019 23:15
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.

5 participants