2021年1月23日星期六

Removing a UWP Grid is too slow

I have a Grid inside ListBox in my UWP application. There is no problem with small grid. However, when a Grid has over 50 cells with multiple rows and columns, removing the grid from its parent is very slow. It takes over 1 minute or about 2 minutes. I tried to hide it by changing its Visibility to Collapsed or Opacity to 0 or building a release executable but still too slow as the same. ToList().Clear() works fast in some case, but not enough.

ListBox rootBox = new ListBox();  rootBox.Items.Add(grid);              // adding a complex Grid with over 50 cells with inner UI elements like TextBlock, TextBox and so on.  rootBox.Items.Remove(grid);     <--- takes about 2 minutes with CPU utilization under 15% in my modern PC  

There's no APIs to suspend and resume layout update in UWP.

Dynamically manipulating a UWP Grid element seems unpractically slow to me.

I tried to find a way to optimize performance for Grid UI, but failed.

Profiling showed me that layout task takes about 50% of CPU of the process but not intensive even in 1 core. It means the slowness is not from CPU-intensive calculation.

https://stackoverflow.com/questions/65859296/removing-a-uwp-grid-is-too-slow January 23, 2021 at 08:39PM

没有评论:

发表评论