UI.WPF.Modern icon indicating copy to clipboard operation
UI.WPF.Modern copied to clipboard

Low performance on ListView, DataGrid with virtualization and massive data

Open AuthorZiXi opened this issue 10 months ago • 11 comments

[Auto-translated]

Describe the bug

I'm sorry to submit another issue in a hurry, and disturb all contributors again. This problem was actually discovered around November of the previous year. (That is, it also existed before

Cause: A file manager that was previously attempted to implement (the progress is irrelevant to the topic, so there is no need to explain it in detail.

After using the style, ListView has a large performance gap, and the situation here may be more extreme (not to mention that there are 3902 ogg files

Fault cause investigation: As long as the style is used, the same phenomenon will occur when trying to virtualize and replace it with datagrid

Specific phenomenon: It causes long-term UI thread jams

Reproduction

When I used the native style, the loading was relatively fast, but after using the style, the performance problem was obvious.

The original recorded video was too large, so I found an online website to compress it

The video is long, if you don't want to watch it, you can try to reproduce it locally. (The video shows the performance difference between ListView without and with styles

https://github.com/user-attachments/assets/26b08b1e-d8b5-4b1d-8530-a1a199ea50ac

This is the ListView of my program file view

<ListView x:Name="FolderView" Background="Transparent" d:ItemsSource="{d:SampleData ItemCount=20}" ItemsSource="{Binding FolderViewItems}" MouseRightButtonUp="FolderView_MouseRightButtonUp"  MouseDoubleClick="FolderView_MouseDoubleClick">
    <ListView.View>
        <GridView x:Name="gridView" AllowsColumnReorder="True">
            <GridViewColumn DisplayMemberBinding="{Binding Name,Mode=OneTime}" Header="名称"/>
            <GridViewColumn Width="120" DisplayMemberBinding="{Binding Size, Mode=OneTime}" Header="大小" />
            <GridViewColumn Width="120" DisplayMemberBinding="{Binding Type, Mode=OneTime}" Header="类型" />
            <GridViewColumn Width="120" DisplayMemberBinding="{Binding ModifyTime, Mode=OneTime}" Header="修改" />
        </GridView>
    </ListView.View>
    <ListView.GroupStyle>
        <GroupStyle>
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <TextBlock Style="{DynamicResource {x:Static ui:ThemeKeys.TitleTextBlockStyleKey}}" Text="{Binding Name, Mode=OneTime}" />
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
        </GroupStyle>
    </ListView.GroupStyle>
</ListView>

Suggested Solution

I don't know how to solve it, but can you provide some directions for investigation: Directory query and data generation will not take a long time, and the UI thread occupation is likely related to control generation (or template).

Can the original virtualization function be restored or re-implemented? Maybe you can try to use other methods instead?

Library Version

1.2.8

Operating System

Windows 11

Framework

.NET Core and .NET

Framework Version

8.0

Source of Package

NuGet.org (Package)

Additional Notes

In addition, the holiday is about to end, and I don’t have much time to give a timely reply (academic issues.

I hope everyone understands!

Validations

  • [x] Check that there isn't already an issue that reports the same or similar problem.
  • [x] Check that this is a bug in the library that should be fixed, not a feature, also this is not about the documentation. (Or please choose the right repo and template.)
  • [x] This is one single problem, or a few problems with the same cause. (If you want to report multiple problems, please create one issue for every single problem.)
  • [x] You've checked that this problem still exists in the latest version. (Keep in mind that we don't provide any support for old versions.)
  • [x] You know that we can't guarantee that we will satisfy your request. This is not really our duty to do everything anyone asks for. Also, you will treat our staff, contributors, and other users with respect and kindness.
  • [x] You're sure there's something wrong with the library itself, not how you're using it. (If you are having issues using it and need help, please go to discussion.)

AuthorZiXi avatar Feb 09 '25 15:02 AuthorZiXi

虚拟化没办法正常使用么?

NotYoojun avatar Feb 09 '25 15:02 NotYoojun

采用了也存在卡顿问题,不知道为什么没有效果(已修订句意

AuthorZiXi avatar Feb 09 '25 16:02 AuthorZiXi

这种模糊又找不到具体原因的问题几乎是很难修的。

NotYoojun avatar Feb 17 '25 05:02 NotYoojun

我这里是在添加数据的时候会卡,后面滚动都不会卡,我用WPFUI或者原生WPF库加载同样的数据没有问题 分批添加可以解决(用户滚动应该没那么快,一次添加一百条延时一会再添加

tmdakm avatar Feb 17 '25 10:02 tmdakm

(from the video description) I had similar problem , and i managed to fix it by changing the default style to this:

`<Border x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="true"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <ContentPresenter Content="{TemplateBinding chelper:ListViewHelper.Header}" ContentTemplate="{TemplateBinding chelper:ListViewHelper.HeaderTemplate}" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> <local:ScrollViewerEx Focusable="false" Grid.Row="1" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" Padding="{TemplateBinding Padding}" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" chelper:ScrollViewerHelper.AutoHideScrollBars="{TemplateBinding chelper:ScrollViewerHelper.AutoHideScrollBars}">

                            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />

                        </local:ScrollViewerEx>
                        <ContentPresenter
                            Content="{TemplateBinding chelper:ListViewHelper.Footer}"
                            ContentTemplate="{TemplateBinding chelper:ListViewHelper.FooterTemplate}"
                            Grid.Row="2"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch" />
                    </Grid>
            </Border>`

basically removing grid from scrollviewer content, as this seems to make the virtualization panel viewport measure the viewport with height of infinity and it keeps realizing all items.

mou-haz avatar Mar 09 '25 17:03 mou-haz

(from the video description) I had similar problem , and i managed to fix it by changing the default style to this:

basically removing grid from scrollviewer content, as this seems to make the virtualization panel viewport measure the viewport with height of infinity and it keeps realizing all items.

This grid is actually used for some animating stuff, which seems necessary, however, I gues it's worth a try to replace it with a Border. Maybe a Grid will cause extra layout calculating, well, or something.

Could you guys pls try the code in the test branch: https://github.com/iNKORE-NET/UI.WPF.Modern/commit/bbfbefe830645ade0c16b86c12039c47c544be42, and see if this is fixed?

NotYoojun avatar Mar 10 '25 18:03 NotYoojun

@AuthorZiXi 感谢您对本项目的认可和贡献!麻烦以后提交的时候请不要说中文,哪怕用咕噜咕噜翻译成英语也行啊

NotYoojun avatar Mar 10 '25 18:03 NotYoojun

This grid is actually used for some animating stuff, which seems necessary, however, I gues it's worth a try to replace it with a Border. Maybe a Grid will cause extra layout calculating, well, or something.

Could you guys pls try the code in the test branch: bbfbefe, and see if this is fixed?

I am really sorry my previous reply was messy,

I tried the fix in the the in the test branch: https://github.com/iNKORE-NET/UI.WPF.Modern/commit/bbfbefe830645ade0c16b86c12039c47c544be42, but it didn't work as it is modifying the ListViewItem style.

What i was suggesting was regarding the grid in the BaseListViewStyle , here is a commit with my suggestion: 65d41a, (I don't remove the grid i just move the ScrollViewer to wrap the ItemsPresenter, but this have the side effect of making the header and footer fixed and only the content scrollable)

** Also, please note that this doesn't eliminate the problem as having layouts with inifinte size like scrollviewer or stackpanel as parent in the visualtree will also cause the problem , but this happens even with the default wpf ListView style.

Here is a minimal project with the defualt iUWM style and my suggestion: VirtualTest

mou-haz avatar Mar 10 '25 20:03 mou-haz

pls use virtualization in right away... and you can have a try SnoopWPF.. 可以试试Snoop...

Image

Yue-cn avatar Mar 20 '25 13:03 Yue-cn

Hi, please check if the branch https://github.com/iNKORE-NET/UI.WPF.Modern/tree/fix-154 fixes your problem. @AuthorZiXi @mou-haz @tmdakm

NotYoojun avatar Mar 24 '25 05:03 NotYoojun

@NotYoojun didn't work for me.

mou-haz avatar Mar 24 '25 17:03 mou-haz