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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[material-ui][Dialog][Tooltip] Improve performance with lots of elements #27879

Open
1 task done
LorenzHenk opened this issue Aug 21, 2021 · 1 comment
Open
1 task done
Labels
component: modal This is the name of the generic UI component, not the React module! component: tooltip This is the name of the generic UI component, not the React module! performance

Comments

@LorenzHenk
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 馃挕

Adding / removing children to / from the HTML body causes the browser to recalculate the children of the body. With many elements this can have a noticeable performance impact.

Temporary elements should be created in a permanent child of body.

Examples 馃寛

This is a contrived example where we're rendering 10000 button elements in the body.
You can clearly see the performance impact on opening the modal dialog.

Bad:
Just use the dialog normally, it will be rendered as direct child of the body.
Opening the modal dialog takes >600ms.
image

Good:
A custom div in the body that is used as container of the dialog.

Opening the modal dialog takes ~65ms.
image

This problem also affects other elements based on the Dialog component, e.g. the Drawer.

This problem could also affect the Tooltip component, though after a quick test I wasn't able to see any notable performance improvements (see this demo).

Note: it seems like chrome (firefox not so much) can handle this if the 10000 buttons are nested (see this demo where the buttons are wrapped in a div).

Motivation 馃敠

I just read this blog post by @atfzl (thx btw!) about performance pitfalls for children of body. I was wondering if this could affect the material-ui components as well.

@LorenzHenk LorenzHenk added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Aug 21, 2021
@eps1lon
Copy link
Member

eps1lon commented Aug 23, 2021

Thanks for the feedback.

We already have work started in #27699 for the Tooltip.

In 4.x and 5.x you can provide a custom container (e.g. a permanent child of document.body) to the Dialog. So if you see performance problems in your app related to document.body, you can fix it.

However, it's not that trivial to make that the default beheavior since we have to consider iframes etc.

But this is something we want to experiment with, document and then hopefully improve the default behavior.

@eps1lon eps1lon added component: modal This is the name of the generic UI component, not the React module! component: tooltip This is the name of the generic UI component, not the React module! performance and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Aug 23, 2021
@ZeeshanTamboli ZeeshanTamboli changed the title [Dialog] Improve performance with lots of elements [material-ui][Dialog][Tooltip] Improve performance with lots of elements Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: modal This is the name of the generic UI component, not the React module! component: tooltip This is the name of the generic UI component, not the React module! performance
Projects
None yet
Development

No branches or pull requests

2 participants