Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
230
When dada source has the value like double.NaN,double.PositiveInfinity,performance is slow
posted

Hi, there is an issue, if the data source of this grid has a lot of value like Double.NaN or Double.PositiveInfinity, the performance is bad, and also ,the sum function is also very slow, how to handle this? do you have any defined constant for those value like in UltraGrid?

I attached a simple  demo ,you can run it and see the performance issue.

WpfApplication5.zip
Parents
No Data
Reply
  • 2070
    posted

     Hi Susie_Zeng,

     

     Most of the performance issue stems from handled first change exceptions when you run the app in debug mode. This becomes less of an issue when the app is run in non-debug mode. However there's definitely an issue with performance when it comes to NaN/Infinity values. We've taken note of this and entered it into our bug tracking system. Further researching into it we've found that the issue occurs with XamMaskedEditor, which is the default editor for double fields, and with the summary calculators. Until we address the issue in our controls, you can use the following workaround.

     

    // Add this line of code before setting the XamDataGrid's DataSource.
    // Default editor for double is XamMaskedEditor which doesn't handle NaN/Infinity efficiently.
    // Therefore change the default editor for double data type to XamTextEditor.
    ValueEditor.RegisterDefaultEditorForType( typeof( double ), typeof( XamTextEditor ), true );

     

    void Window1_Loaded(object sender, RoutedEventArgs e)
    {
        // Register our derived MySumCalculator class (see below) and use that instead of built-in
        // SumSummaryCalculator.
        SummaryCalculator.Register( MySumCalculator.Instance );
        XamDataGrid1.DefaultFieldLayout.SummaryDefinitions.Add( MySumCalculator.Instance, "col3" );
        XamDataGrid1.DefaultFieldLayout.SummaryDefinitions.Add( MySumCalculator.Instance, "col4" );
        XamDataGrid1.DefaultFieldLayout.SummaryDefinitions.Add( MySumCalculator.Instance, "col5" );
        XamDataGrid1.DefaultFieldLayout.SummaryDefinitions.Add( MySumCalculator.Instance, "col6" );
    }

    // Derive a new Sum calculator class and override Aggregate to handle NaN/Infinity values.
    private class MySumCalculator : SumSummaryCalculator
    {

        public static readonly MySumCalculator Instance = new MySumCalculator( );
        
        public override void Aggregate( object dataValue, SummaryResult summaryResult, Record record )
        {
            if ( dataValue is double )
            {
                double val = (double)dataValue;
                if ( double.IsNaN( val )
                    || double.IsNegativeInfinity( val )
                    || double.IsPositiveInfinity( val ) )
                    return;
            }

            base.Aggregate( dataValue, summaryResult, record );
        }
    }

     

    Hope this helps,

    Sandip

Children
No Data