movra
Topic Author
Posts: 70
Joined: 02 Apr 2014, 20:35

ListBox ItemsSource performance

16 Sep 2015, 11:47

I'm having performance problems with ListBoxes. Setting the ItemsSource of a ListBox is very slow in NoesisGUI. It's especially a problem for MVVM which heavily depends on a data-driven workflow with ViewModels and Collections therein.

For a simple test I've used just a single ListBox and left out any UserControls, CodeBehinds and MVVM stuff which I should address in another topic.
<UserControl 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    mc:Ignorable="d"
    Height="768" Width="1024" MinHeight="720" MinWidth="1024"
>
    <Grid>
         <ListBox x:Name="MyList" FontSize="24" Height="500" Width="300" />
    </Grid>    
</UserControl>
using Noesis;
using System.Collections.Generic;
using UnityEngine;

public class TestMyList : MonoBehaviour
{
    public int amt = 10;

    private void Start()
    {
        var gui = GetComponent<NoesisGUIPanel>();
        var root = gui.GetContent();
        var MyList = root.FindName<ListBox>("MyList");

        List<string> myStrings = new List<string>(amt);
        string text = "My String #";
        for (int i = 0; i < amt; i++)
        {
             myStrings.Add(string.Concat(text, i));
        }

        MyList.ItemsSource = myStrings;
    }
}
A test with 100 items shows there's a lot of boxing and p/invoking going on behind the scenes. It's not only slow but also causes a lot of allocations.

http://imgur.com/MMtAjOI


Benchmark with 10,000 items

In Visual Studio 2015 the application launches in a blink of an eye.

http://imgur.com/R6T4wsm

In Unity 5.2 it takes minutes. Look at that GPU number :shock:

http://imgur.com/XSyqywD

The standalone build takes over 2 minutes to launch.

Now you may think what am I going to do with 10,000 items, but a card game like Scrolls (made in Unity) or Magic (about unique 12,000 cards) can display lists with several 100s or 1000s of cards.
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: ListBox ItemsSource performance

17 Sep 2015, 14:13

This behavior is totally unacceptable. There are several problems involved here, mainly a clipping problem but the fact that the clipping is not working is also exposing an inefficiency in the way databinding to c# properties is being done.

Could you please create a ticket for this issue?

Thanks and sorry for the inconvenience.
 
movra
Topic Author
Posts: 70
Joined: 02 Apr 2014, 20:35

Re: ListBox ItemsSource performance

17 Sep 2015, 15:30

Created Issue #720.

ItemsControl is much faster than ListBox, so indeed it seems to be not only a problem with the ItemsSource.

Adding 10,000 items
ItemsControl: 30 seconds
ListBox: 2 and a half minute
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: ListBox ItemsSource performance

17 Sep 2015, 15:45

Yes, although 30 seconds is still a lot of time...

Thanks for the report and feedback!

Who is online

Users browsing this forum: No registered users and 1 guest