Skip to content

Bad material-ui Box performance #21657

@alexd16

Description

@alexd16

Seeing significant performance degradation when using Box components to style list item when iterating over arrays

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

When rendering components that use a lot of Box components, I see a visible slowdown in the UI and stops interaction across other elements in the application, which doesn't happen with native components.

Expected Behavior 🤔

I should not see that much of a performance degradation for using the Box component

Steps to Reproduce 🕹

Here is a codesandbox sample that shows the issue: https://codesandbox.io/s/hidden-smoke-hdhe6

Steps:

  1. Click 'Show Div List'
  2. Data will show without any delay
  3. Click 'clear'
  4. Click 'Show Box List'
  5. After a small delay the data shows

Looking at the performance tab on chrome, this is what I see:
Box List
Div List

To be honest I am not too familiar with the performance tab, so I am not sure if what I measured is relevant. But if I am looking at this correctly it seems to be more than 10x performance degradation.

Context 🔦

I have been having some performance issues in the project i've been working on, yesterday I tried to investigate why those issue where happening, and after digging a bit, it seems the reason why I am seeing bad performance across the application is because of our usage of the Box component

Given I didn't saw any warning in the docs I freely used the Box component across the application without expecting performance issues. A lot of styling in the application is done this way.

If this is something that can't be solved, and it's just the overhead that the Box component introduces, I think there should be a notice on the Box component component page so that people avoid this type of usage.

Your Environment 🌎

Tech Version
Material-UI v4.8.3
React v16.13.1

Metadata

Metadata

Assignees

Labels

component: BoxThe React component.performancepriority: importantThis change can make a difference.scope: systemThe system, the design tokens / styling foundations used across components. eg. @mui/system with MUIv4.x

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions