This is a migrated thread and some comments may be shown as answers.

Extremely poor performance when updating lots of cells values

2 Answers 63 Views
GridView
This is a migrated thread and some comments may be shown as answers.
BENN
Top achievements
Rank 1
BENN asked on 21 Nov 2012, 03:25 PM
When updating values of like 1000 cells every 500ms (for example), the UI would lock.
I also did this experiment with 100ms update rate, and the grid was not able to handle it.

The reason I'm checking it is because in my project, I'm connected to a remote hardware from which I read a byte array that represents the data of the cells.
I already wrote the mechanism that knows which rows are visible and therefore reads only the byte array that corresponds the visible rows.
Updating values on none visible rows should almost have no affect because of the UI virtualization.
I know that there is a chance that some cells on the DataTable (my ItemsSource) will not have their value changed on the remote hardware (and in this case I can optimize my code, so it won't overwrite the value, to prevent notification to the UI), but in my example, I'm taking the worst case scenario....


I have decided to check it with some more data grids.

Syncfusion - Almost the same poor performances.
Component One FlexGird - Good performance but lots of bugs (values doesn't get updated after scroll etc).
Micorsoft DataGrid - Good performance
ListView with GridView - Very good performance.


Another thing, GroupRenderMode="Flat" should increase the scroll performance (at least from what your documentation says), but it actually makes it worse!


Is there a better way of doing what I do? (Is there a way of getting the performance at least near the ListView or the DataGrid?)
Thanks.


I'm unable to attach the solution, but here is the code:

    public abstract class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
 
        public void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
 
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Threading.Tasks;
using System.Threading;
 
namespace WpfGridsPerformanceTest
{
    public class MainViewModel : ViewModelBase
    {
        private MyDT _data;
        private DelegateCommand _changeValuesCommand;
 
        public MainViewModel()
        {
            _data = new MyDT();
 
            for (int i = 0; i < 400; i++)
            {
                DataRow row = _data.NewRow();
                _data.Rows.Add(row);
            }
        }
 
        public DataView Items
        {
            get
            {
                return _data.DefaultView;
            }
        }
 
        public DelegateCommand ChangeValuesCommand
        {
            get
            {
                if (_changeValuesCommand == null)
                {
                    _changeValuesCommand = new DelegateCommand(changeValues);
                }
 
                return _changeValuesCommand;
            }
        }
 
        private void changeValues()
        {
            Task t = new Task(() =>
            {
                while (true)
                {
                    foreach (DataRow row in _data.Rows)
                    {
                        for (int i = 0; i < row.ItemArray.Count(); i++)
                        {
                            row[i] = (int)row[i] + 1;
                        }
                    }
 
                    Thread.Sleep(500);
                }
            });
 
            t.Start();
        }
    }
}
 
 
 
<Window x:Class="WpfGridsPerformanceTest.MainWindow"
        xmlns:local="clr-namespace:WpfGridsPerformanceTest"
        Title="MainWindow" Height="350" Width="525" WindowState="Maximized">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
 
        <local:Telerik />
         
        <!--<local:Syncfusion />-->
         
        <!--<local:DataGrid />-->
         
        <!--<local:ListView />-->
        <Button Grid.Row="1" FontWeight="Bold" FontSize="16" Command="{Binding ChangeValuesCommand}">Click to start changing values</Button>
    </Grid>
</Window>
 
 
 
 
 
 
 
 
 
<UserControl x:Class="WpfGridsPerformanceTest.Telerik"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <telerik:RadGridView ItemsSource="{Binding Items}"
                             ShowGroupPanel="False"
                             UseLayoutRounding="False"
                             RowIndicatorVisibility="Collapsed"
                             DataLoadMode="Synchronous"
                             CanUserFreezeColumns="False"
                             CanUserSortColumns="False"
                             CanUserSelect="True"
                             SelectionMode="Single"
                             SelectionUnit="FullRow" />
    </Grid>
</UserControl>

2 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 21 Nov 2012, 04:13 PM
Hello,

Please set ValidatesOnDataErrors="None" for the grid to fix this. The main problem comes from the fact that DataAnnotations validation does not work well with ICustomTypeDescritptor (DataView in your case) - will raise invalid property name exceptions. RadGridView validation is on by default and these exceptions are catched however you may get performance problems in such cases. 

I'm attaching an example project for reference. I've removed the Thread.Sleep. 

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
BENN
Top achievements
Rank 1
answered on 22 Nov 2012, 06:09 AM
Thanks, that helped a little.
After changing few more properties, I've set the ColumnWidth to be const which greatly improved the performance.

Thanks for your help.
Tags
GridView
Asked by
BENN
Top achievements
Rank 1
Answers by
Vlad
Telerik team
BENN
Top achievements
Rank 1
Share this question
or