-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[Modal] performance #17196
Comments
@priscilawebdev Thanks for the detailed report. There is one aspect that I think we miss. Why is the dialog component concerned with the issue? It seems that most of the time is spend outside Material-UI. |
Thank you for opening this detailed performance report! From what I can tell 1s alone is spent rendering the There are some possible improvements for this scenario but they all involve unstable react features. If What would be possible is to not render the DialogContent until you decide you have enough render resources to spare. You would render the dialog initially with |
For example something like this: https://codesandbox.io/s/crude-offscreen-render-5tfxu This is what |
@eps1lon, @oliviertassinari thank you for your prompt reply! @eps1lon Yes the Hmmm interesting 'possible solution' with the heuristic and My findings will be posted here 😉 |
May or may not be relevant to this issue, but I have a question regarding the Doc talking about the performance of modals. Basically it says A is bad, and B is good: // A:
const [open, setOpen] = useState(false);
return <Modal open={open}>{/* lots of JSX here */}</Modal>;
// B:
const [open, setOpen] = useState(false);
return <Modal open={open}><ReturnLotsOfJSX /></Modal>; A is bad because the modal is always rendered even when Which raises some questions:
const [open, setOpen] = useState(false);
return open && <Modal open={open}>{/* lots of JSX here */}</Modal>;
const [anchorEl, setAnchorEl] = useState(null);
return (
<Menu open={!!anchorEl} anchorEl={anchorEl}>
{/* lots of JSX here */}
</Menu>
) |
@ZYinMD It's not "bad". Just because something isn't needed doesn't mean it's bad or needs optimization. The first rule of performance is that you measure. Don't look at the code and find the lines that aren't needed. Measure what is happening. If you see issues then and only then should you take action. The issue described in the section is not about rendering but I'll do a benchmark and compare the approaches. If it's insignificant we can cut the section. Though this isn't relevant to this issue. @ZYinMD If you have any more questions please open a separate issue. |
Thanks @eps1lon , I'll create a separate issue, since I really want to learn about the best practice for |
@priscilawebdev Do you have a reproduction for this issue with the Modal? |
@oliviertassinari I am sorry, but I don't have it. It is very difficult to create an example similar of what we have here...we render many components that make use of hooks that create and inject 1) empty styles 2) synchronously. This is very expensive. The possible solution with the heuristic + the keepMounted suggested by @eps1lon unfortunately, for some reasons, it is not ideal to solve our problem. I also noticed that even using keepMounted 'correctly', some actions freeze. Ex: I can't click on any button for a few seconds. After analyzing the Dynamic component and giving a proper name to the anonymous functions we have. I concluded that this performance issue is related to this issue created by my co-worker: #16756 |
Great, we can close this issue then :) |
Firstly, I would like to thank you for all your efforts in building this amazing library. We love using it.
It is related to this issue: #10778, but as @oliviertassinari said this "I'm closing this issue. We need a dedicated performance report for each potential area of improvement, not an umbrella thread." I decided to open a separate issue. So..
Current Behavior 😯
We are currently experiencing performance issues rendering the Dialog component as a child of other components rendered inside a map() method.
The Dialog components open with considerable delay. For instance:
The Dialog takes longer than 3s to open.😬
After reading more about the Dialog API documentation, I decided to try the "keepMounted" prop. I noticed a improvement performance, but pages takes long to finally render.. Please see:
Page loads - before keepMounded:
Page loaded - after keepMounted:
Dialog component - with keepMounted:

So after read about the modal performance issue and how to solve it "You can speed up the rendering by moving the modal body into its own component.". I decided to try it out, but even after moving the dialog body into its own component the problem persisted.
Expected Behavior 🤔
The Dialog component should not open with a delay. The performance should be improved.
Context 🔦
Desktop version
Your Environment 🌎
The text was updated successfully, but these errors were encountered: