Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI Potential Slow Performance of withStyles

I'm tasked with making a page in our react redux web app load faster.

When the action for loading the page triggers we get what appears to be a small freeze of roughly .5 sec.

I have the profiler open and at first glance nothing seems to be wrong.
Flame Graph

There are no unnecessary rerenders, and the only yellow warning that is shown is roughly 10 milliseconds.

When I go to the ranked tab in the profiler I get a slightly different story where I find that the majority of the time is spent in withStyles().
Ranked Graph

We use the material-ui approach of CSS in JS via withStyles() and it appears as if the use of WithStyles() is significantly affecting the load speed.
Is this the case? or is this simply a case of "I'm rendering too many things at once"

It would be a significant effort to convert the CSS in JS to just CSS, although I did spend an hour ripping out the CSS in JS and found a performance improvement of about 40% although it is unknown to me how much of that 40% is due to the withStyles versus just the performance of styling elements on a page.

like image 486
moondc Avatar asked Jul 29 '19 16:07

moondc


People also ask

Is material UI good for performance?

Material UI provides developers with material-based UI components. They help save some time on design and app development. But since Material UI is mostly a set of UI components, it doesn't offer such a great boost to the development speed as Bootstrap does.

Is material UI slow?

Material-UI and typescript is extremely slow in autocompleting and rendering errors. (2022)

Is material UI SEO friendly?

You can easily develop highly engaging and SEO-friendly websites with excellent performance and efficiency. By integrating Material UI into your React applications, you can elevate your web development experience to the next level and build dynamic and high-quality websites.

What is the advantage of material UI?

It includes a comprehensive collection of prebuilt components that are ready for use in production right out of the box. Material UI is beautiful by design and features a suite of customization options that make it easy to implement your own custom design system on top of our components.


1 Answers

+90% of the time spent in WithStyles is actually spent in JSS, there very few we can do about it on Material-UI side.

From

Although, there is a possible speed up that doesn't include re-writing you JS CSS styling approach, which is switching to makeStyles instead of withStyles

Can be found out here

like image 104
Sultan H. Avatar answered Sep 18 '22 15:09

Sultan H.