-
Notifications
You must be signed in to change notification settings - Fork 852
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
[Menu] Each Menu adds its own document event listeners for detecting keyboard state #1239
Comments
@benoitgrelard @jjenzz Just pinging this. This is causing serious overhead in our app. It would be great if we could have a solution in Radix that didn't incur a performance penalty for each additional menu. Thanks! |
Looking at the code it seems any component using the following components could add N (N = number of components) listeners to the app causing it to be slow once the app gets large enough:
|
@hipstersmoothie many of the components listed would only add events when the content parts are open so unlikely to be an issue unless you have 1000s of dialogs open at the same time (for example). the issue with |
@AlabasterAxe how many menus do you have rendered on your page? i'm not working at modulz anymore so i cannot help with a timeline for a solution to this i'm afraid but i'm surprised it is causing such a significant slow down. you can see up to 500 menus (that also open dialogs) here performing fine: https://codesandbox.io/s/radix-performance-demo-forked-o6q977?file=/src/App.js |
Nice thanks for the pointer! taking a look. I agree that example performs very well. Not sure why performance would be so different. In the cases I've been looking at it was ~700. |
Yeah this is easily reproducible with the given example. Here I upped the menus to 1000 and each keydown takes 140ms Even downing it to 700 (matching our usage) see This PR I opened does fix the issue though. 🙏ing we can get a merge |
while i agree it might be nice to reduce these events (to prevent the overhead of these reports if anything), if you're experiencing a performance issue from them i would think you are rendering far too many menus at once. personally i would avoid rendering 500 menus let alone 1000 since it is unlikely to be possible for a human to interact with that many menus in a single viewport, so react will be redundantly managing those trees. using something like IntersectionObserver/virtual scroll to render only the menus in the user's viewport will help your performance all round. |
@jjenzz 100% agree, there's no reason we need to render many of those components since most of them are off-screen. I'm planning on looking into this soon. At the same time, I think it's reasonable for these components to defensive about potential misuse, especially since in this case it seems like there are reasonable ways to avoid registering one listener per menu. |
Hi @AlabasterAxe,
Whilst this might be nice, it is clear that a lot more can be done user-side/app-side to ensure better performance. We have to prioritise where we focus our time so I will close this issue for now as it is unlikely we will do more in this case. ✌️ |
Bug report
This is basically a reopening of #1139 since we're still seeing considerable slow down even after updating past the fix.
Current Behavior
Radix Dropdown Menus and Context Menus each add their own document event listeners for keydown and pointerdown which can cause a slowdown in the handling of the corresponding events
Expected behavior
Handling of keydown and pointerdown don't slowdown as a result of additional menu components on the page.
Reproducible example
Reproduction is to add n menus to a react app and observe that there are n document event listeners for either keydown or pointerdown
My Profile demonstrating consistent slowness with handling mousedown events:
Profile-20220312T073820.json.zip
And here's a screenshot from the above profile demonstrating a couple of examples of keydown events that take over a second to handle:
Suggested solution
Provide a global keyboard state context which registers a single document event listener and all menus can share.
Your environment
The text was updated successfully, but these errors were encountered: