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

Alternating rows performance

5 Answers 162 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 09 Oct 2017, 07:58 AM

I identified performance loss while using Alternating rows.

Based on already existing posts: http://www.telerik.com/forums/alternating-rows-hurts-performance

I implemented my own RowStyle selector:

    public class RadGridViewAlternatingRowTemplateSelector : StyleSelector
    {
        private static int counter = int.MinValue;

        public override Style SelectStyle(object item, DependencyObject container)
        {
            return (counter++ % 2) == 0 ? EvenRowStyle : OddRowStyle;
        }

        public Style EvenRowStyle { get; set; }
        public Style OddRowStyle { get; set; }
    }

I tried to keep it as short and simple as possible for a maximum performance.

    <template:RadGridViewAlternatingRowTemplateSelector x:Key="AlternativeRowStyleSelector">
        <template:RadGridViewAlternatingRowTemplateSelector.EvenRowStyle>
            <Style TargetType="telerik:GridViewRow" BasedOn="{StaticResource GridViewRowStyle}">
                <Setter Property="Background" Value="{DynamicResource RowBackgroundColor}"/>
            </Style>
        </template:RadGridViewAlternatingRowTemplateSelector.EvenRowStyle>
        <template:RadGridViewAlternatingRowTemplateSelector.OddRowStyle>
            <Style TargetType="telerik:GridViewRow" BasedOn="{StaticResource GridViewRowStyle}">
                <Setter Property="Background" Value="{DynamicResource SecondRowBackgroundColor}"/>
            </Style>
        </template:RadGridViewAlternatingRowTemplateSelector.OddRowStyle>
    </template:RadGridViewAlternatingRowTemplateSelector>

 

 <Style TargetType="{x:Type telerik:RadGridView}" BasedOn="{StaticResource RadGridViewStyle}">
        <Setter Property="RowStyleSelector" Value="{StaticResource AlternativeRowStyleSelector}" />
        <Setter Property="GridLinesVisibility" Value="Vertical" />
        <Setter Property="ValidatesOnDataErrors" Value="InEditMode" />
        <Setter Property="AutoGenerateColumns" Value="False" />
        <Setter Property="VerticalAlignment" Value="Stretch" />
        <Setter Property="HorizontalAlignment" Value="Stretch" />
        <Setter Property="IsReadOnly" Value="True" />
        <Setter Property="ShowGroupPanel" Value="False" />
        <!--<Setter Property="ShowColumnSortIndexes" Value="False" />-->
         <!--This is not possible, because no DP!--> 
        <Setter Property="RowIndicatorVisibility" Value="Collapsed" />
        <Setter Property="IsFilteringAllowed" Value="False" />
        <Setter Property="CanUserSortColumns" Value="False" />
        <Setter Property="CanUserSortGroups" Value="False" />
        <Setter Property="CanUserReorderColumns" Value="False" />
        <Setter Property="CanUserResizeColumns" Value="False" />
        <Setter Property="CanUserResizeRows" Value="False" />
        <Setter Property="CanUserFreezeColumns" Value="False" />
        <Setter Property="FontSize" Value="{DynamicResource FontSize}" />
        <Setter Property="FontFamily" Value="{DynamicResource FontFamily}" />
        <Setter Property="EnableColumnVirtualization" Value="False" />
        <Setter Property="EnableRowVirtualization" Value="True" />
        <Setter Property="GroupRenderMode" Value="Flat" />
    </Style>

In addition, I tried using NoXAML assemblies (as you can see at my style definition) to even squeeze more performance out of Telerik controls.
Summary: NoXAML Assemblies, Own Style Selector, GroupRenderMode Flat, other properties in Style, RadGridView in * Grid Row,...
There isn't any single point left I could optimize (refering to this article: http://docs.telerik.com/devtools/wpf/controls/radgridview/troubleshooting/performance)

The performance is pretty damn nice if I use no alternating rows.
But when I use them (and I definitely have to, with or without Telerik) the performance drops to an unacceptable point.

So my question here is: Is there anything I can do to speed things up? Are there any updates on alternating row performance?

Thanks in advance

 

5 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 12 Oct 2017, 06:33 AM
Hi,

Performance of AlternateRowStyle and RowStyle (and their StyleSelector counterparts) strongly depends on the style that is being applied. Actually, on the template in particular. When NoXAML binaries are used, styling is carried out by the WPF implicit styles mechanism. However, when a StyleSelector that applies a style with a different template from that of the implicit style is used, loading a row instance causes it to reapply the template. Reapplying the control template is the operation that hits performance. I prepared a sample project based on the information that you provided, which is attached to this post. The style named "style1" defines a template that is different from the default one. You can observe how adding and removing the custom implicit style affects performance (uncomment the respective line In App.xaml). 

Regards,
Ivan Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Thomas
Top achievements
Rank 1
answered on 12 Oct 2017, 06:18 PM

Hi,

I did try your example and I am kinda confused. You didn't set any template, just applied the GridViewRowCoreStyle to the GridViewRow. Isn't that already the case if there is no style set? And since you use:

 

...
<my:AStyleSelector>
<my:AStyleSelector.Style1>
<Style TargetType="telerik:GridViewRow" BasedOn="{StaticResource GridViewRowCoreStyle}">
<Setter Property="Background" Value="{DynamicResource Brush1}" />
</Style>
</my:AStyleSelector.Style1>
<my:AStyleSelector.Style2>
<Style TargetType="telerik:GridViewRow" BasedOn="{StaticResource GridViewRowCoreStyle}">
<Setter Property="Background" Value="{DynamicResource Brush2}" />
</Style>
</my:AStyleSelector.Style2>
</my:AStyleSelector>

...

 

which does set a Style for telerik:GridViewRow, isn't

<Style TargetType="telerik:GridViewRow" BasedOn="{StaticResource GridViewRowCoreStyle}" />

in App.xaml reduntant and automatically overridden?

Sorry If I do ask basic questions here, but for me, currently, it makes no sense.

0
Ivan Ivanov
Telerik team
answered on 17 Oct 2017, 03:04 PM
Hello,

Please excuse me for the delayed reply. GridViewRowCoreStyle defines a control template that is different from the one that is applied by the implicit style for GridViewRow. In this way, a row first receives the implicit style and sets the control template that is applied by it, which is a rather slow action. Then the style selector applies another style, which defines another template. WPF uses some sort of caching system to guess that if control template is the same, the row does not need to get re-templated. However, if you uncomment the row that you mentioned:
<Style TargetType="telerik:GridViewRow" BasedOn="{StaticResource GridViewRowCoreStyle}" />
The active implicit style will be based on GridViewRowCoreStyle - the same that is used as a base type for the selector styles. In this way, there will be no need to reset the template multiple times and run-time perfromance will be better. If you think that the suggested approach can be beneficial for your scenario, I will be glad to help you with guidance.

Regards,
Ivan Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Thomas
Top achievements
Rank 1
answered on 17 Oct 2017, 03:22 PM

Hello Ivan!

Thanks for the detailed explanation. I do understand now why there was such a huge performance loss.
I have already switch to your suggested approach and everything works fine at the moment. (Not 100% smooth and still some laggs here and there, but acceptable delays)

Thank you very much.

Regards

0
Ivan Ivanov
Telerik team
answered on 18 Oct 2017, 07:20 AM
Hello,

I am glad to hear that you managed to achieve the desired behavior. Please do not hesitate to contact us again if you need any additional guidance with our controls.

Regards,
Ivan Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Thomas
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Thomas
Top achievements
Rank 1
Share this question
or