MudSelect rerenders content every time, resulting in bad performance

See original GitHub issue

Bug type

Component

Component name

MudSelect

What happened?

I would like to make a country selector for a registration form using MudSelect. I have a countries.json with all country names, iso codes and flag base64 images.

I m rendering the dropdown with this code: <MudSelect Label="Country" Variant="Variant.Text" OffsetY="true" @bind-Value="registrationRequestDto.CountryAlpha3Code" For="@(() => registrationRequestDto.CountryAlpha3Code)"> @foreach (var country in countries) { <MudSelectItem Value="country.IsoAlpha3"> @* <img src="data:image/png;base64,@country.Flag" height="14" class="mr-2" />*@ @country.Name </MudSelectItem> } </MudSelect>

I have commented out the flag image part, and set them all to null, but the dropdown is still very slow.

Every time I open the dropdown or close it (either by clicking on an element, or clicking outside the dropdown) the foreach runs, and it creates 200+ MudSelectItems. This results in the UI totally freezing up for 1 second.

Expected behavior

I expected it to create the listitems once, and use it whenever I open the dropdown.

This might be a general Blazor issue \ question, but I think I have the best chance for help here.

Reproduction link

https://try.mudblazor.com/snippet/wOQFlucQyPhgdvTA

Reproduction steps

  1. Click on dropdown
  2. Notice the 1second delay

Relevant log output

No response

Version (bug)

5.1.5

Version (working)

No response

What browsers are you seeing the problem on?

Chrome

On what operating system are you experiencing the issue?

Windows

Pull Request

  • I would like to do a Pull Request

Code of Conduct

  • I agree to follow this project’s Code of Conduct

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
iwiscommented, Jan 20, 2022

In this example the virtualization seems to work fine, but after the MudSelect there are a lot of empty lines.

You can remove the empty space by putting MudSelect in <div style="height:65px;overflow-y:hidden;"> ... </div>. See https://try.mudblazor.com/snippet/QammubwEBhQtuWUo and https://docs.microsoft.com/en-us/aspnet/core/blazor/components/virtualization?view=aspnetcore-5.0

1reaction
Atee134commented, Oct 27, 2021

Thank you for the feature request.

Indeed you’re right. I am running it in WASM. I have tried the multi select now in WASM mode on mudblazor.com and I see a small hiccup there as well when clicking on one of the options in the dropdown. However, it’s only around a 190ms delay, which is only noticeable if you look for it.

But on my site for some reason, it’s around 900ms

Read more comments on GitHub >

github_iconTop Results From Across the Web

MudSelect, MudTable: Performance problems with large ...
Very very poor performance on MudSelect in a MudTable with 30+ rows and ... all of the delegates each time the MudSelectItem are...
Read more >
React performance issues caused by rerendering
When you fix all your callbacks you can boost performance. At this time, your code cause rerender of all items almost every small...
Read more >
Optimizing React Performance By Preventing Unnecessary ...
Re-rendering React components unnecessarily can slow down your app and make the UI feel unresponsive. This makes the user experience worse ...
Read more >
ASP.NET Core Blazor performance best practices
Tips for increasing performance in ASP.NET Core Blazor apps and avoiding common performance problems.
Read more >
How to identify and resolve wasted renders in React
Building a React app where the differentiating algorithm fails to reconcile effectively, causing the entire app to be rendered repeatedly which ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found