mui / toolpad

Toolpad: Full stack components and low-code builder for dashboards and internal apps.
https://mui.com/toolpad/
MIT License
964 stars 243 forks source link

Performance degradation on the example app #2139

Closed Janpot closed 1 year ago

Janpot commented 1 year ago

Steps to reproduce 🕹

Steps:

  1. Run and profile the example application: https://github.com/mui/mui-toolpad/pull/2096
  2. Notice the app being very sluggish, up to a point we can call it unusable.
  3. Record a performance trace
  4. Notice it renders on every keystroke and the renders take about ~200 - ~250ms to complete (I'm on a Macbook air M1):

    Screenshot 2023-06-06 at 13 32 29

Current behavior 😯

It's just too slow. Did a quick code review and the biggest contributor to this sluggishness seems to be because we are recalculating the state for the whole page on every node we render. This is a regression that was likely introduced when we added nested scopes to the runtime to enable List and Form components. Before that the whole page used to be calculated on every keystroke, but only once. This is also a bit wasteful, but nothing compared to doing it on every node which turns a O(n) algorithm into O(n^2) (n being the amount of nodes on the page).

Expected behavior 🤔

The page state is only calculated once for the whole page

apedroferreira commented 1 year ago

I didn't notice at the time but those changes might have an impact on the performance... Thanks for looking into it, let me know if I can help with anything!

Edit: also we could try to create some automated checks for performance eventually, it might be useful to prevent this kind of issue