5

I have performance issue with ListView:

Single item takes 13-30 ms to create (50 items is over 1 second). Virtualization (recyling mode) is on, but scrolling even 100 items is already very uncomfortable.

At first I thought it's layout problem. But the reason seems to be - bindings.

There are multiple columns and each column cell has different template with different bindings, as an example:

<GridViewColumn>
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <Grid>
                <TextBlock Text="{Binding Value}"
                           Visibility="{Binding IsEditable, Converter={local:TrueToCollapsedConverter}}" />
                <Grid local:GridBehavior.Columns=",auto"
                      Visibility="{Binding IsEditable, Converter={local:FalseToCollapsedConverter}}">
                    <TextBox Text="{local:ExceptionBinding Path=Value, Converter={local:DoubleToStringConverter}}"
                             local:TextBoxBehavior.SelectAllOnFocus="True"
                             local:ListBoxBehavior.SelectListBoxItemOnFocus="True" />
                    <TextBlock Grid.Column="1" Text="{local:Lng Key=Unit.mm}" />
               </Grid>
           </Grid>
       </DataTemplate>
   </GridViewColumn.CellTemplate>

Any single binding add something like 0.1 ms. There are 20 columns, each cell has from 1 to 20 bindings, so it leads to this:

Binding take majority of time, e.g. 2.83 of 3.07 ms for the first column on screenshot.

Is there a way to gain some performance? Am I doing some obvious mistake?

Ibrahim Hamaty
  • 540
  • 2
  • 18
Sinatr
  • 20,892
  • 15
  • 90
  • 319
  • 1
    Do you get any performance improvements if you remove your customizations, such as the Converters, custom `ExceptionBinding`, `local:Lng`, or `local:GridBehavior`? Bindings are meant to be fast, so I would start looking to remove your customized items one at a time and see if the removal shows any significant improvement. Also, you didn't overwrite the `Template` at all did you? I know that can remove the virtulization, but a quick check of how many items are rendered with a tool to snoop the application should verify that virtualization is working (or not) – Rachel Jul 07 '16 at 15:31
  • @Rachel, removing customization doesn't change figures. `VirtualizingStackPanel` is parent, so virtualization is on. If I disable virtualization the loading time of `ListView` is increased (as opposed scrolling become better) and doesn't affect numbers of individual `ListViewItem` (which I am interested to improve). I tried to remove binding and add them (as I did yesterday which results in posting this question), but I've got so confusing numbers... I don't think it's binding right now... It looks like simple adding element (e.g `Grid`) to template adds 0.5 ms. Which is a lot... – Sinatr Jul 08 '16 at 12:26
  • 2
    If anyone reads this, the real reason of my performance problems were bindings to a properties with expensive getter (e.g. `Directory.GetFiles()`). – Sinatr May 26 '21 at 08:22

0 Answers0