Page 1 of 1

Bug when setting series visibility in Silverlight

Posted: Thu Sep 08, 2011 12:15 pm
by 15657376
There seems to be a serious performance issue when setting the visibility of a series multiple times in teechart silverlight dll version 4.1.2011.7283.

The following silverlight user control contains a TChart with a single series of 10 random points. Each second the visibility of the series is switched. For the first ~10 ticks, the application works as expected; the series is shown for a second, hidden for a second and repeats.

However, for each tick, the time used to show the series increases. After ~10-20 ticks, showing the series is so slow it never even shows up!

This completely breaks my current application, so I request it to be fixed as soon as possible.


MainPage.xaml

Code: Select all

<UserControl x:Class="TestTeeChart.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:TC="clr-namespace:Steema.TeeChart.Silverlight;assembly=TeeChart.Silverlight"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <TC:TChart x:Name="TChart" Height="300" Width="400" />
</UserControl>
MainPage.xaml.cs

Code: Select all

using System;
using System.Windows.Controls;
using System.Windows.Threading;
using Steema.TeeChart.Silverlight.Styles;

namespace TestTeeChart
{
    public partial class MainPage : UserControl
    {
        private Points series;

        public MainPage()
        {
            InitializeComponent();
            
            // Create and add seres
            TChart.Series.Add(series = new Points());

            // Fill random data
            Random r = new Random();
            for (int i = 0; i < 10; i++)
                series.Add(i, r.Next());
            
            // Create and start timer
            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, 0, 1);
            timer.Tick += (s, a) => { series.Visible = !series.Visible; };
            timer.Start();
        }
    }
}

Re: Bug when setting series visibility in Silverlight

Posted: Fri Sep 09, 2011 9:45 am
by 10050769
Hello PCCUser,

Thanks for your code. I you need know, representing data graphically, that is, drawing data as a chart, is a time consuming process. TeeChart needs to be given time to complete this process, which in a multi-threaded environment means not giving it more data until it has finished painting the last dataset it has been given. The way to check if a TeeChart is painting or not is a flag in the BeforeDraw and AfterDraw events, a flag we could internalise as a property but which would do exactly the same.

You might consider caching charts in your application so that the same chart doesn't have to be created time and time again. In this way new charts are created only when the data has changed, greatly reducing the load on the TeeChart routines.

I hope will helps.

Thanks,

Re: Bug when setting series visibility in Silverlight

Posted: Fri Sep 09, 2011 10:31 am
by 15657376
I think you are misunderstanding my message. The problem is not that rendering the chart is too slow, but that the render time increases every time it is shown (e.g. due to a memory leak). For a more quantitative result, replace the MainPage.xaml.cs with the code below.

Code: Select all

using System;
using System.Windows.Controls;
using System.Windows.Threading;
using Steema.TeeChart.Silverlight.Styles;

namespace TestTeeChart
{
    public partial class MainPage : UserControl
    {
        private Points series;
        private int then;

        public MainPage()
        {
            InitializeComponent();
            
            // Create ad add seres
            TChart.Series.Add(series = new Points());

            // Fill random data
            Random r = new Random();
            for (int i = 0; i < 10; i++)
                series.Add(i, r.Next());
            
            // Create and star timer
            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, 0, 1);
            timer.Tick += (s, a) => { series.Visible = !series.Visible; };
            timer.Start();

            TChart.BeforeDraw += (s, e) =>
            {
                timer.Stop();
                then = Environment.TickCount;
            };
            TChart.AfterDraw += (s, e) =>
            {
                int now = Environment.TickCount;
                int used = now - then;
                then = now;
                timer.Start();
            };
        }
    }
}
If you observe (e.g. add a tracepoint) the used variable on line 39, you will see that the time for showing the chart increase to unaccaptable levels. Here is an example of my times

Code: Select all

Used 94 ms
Used 109 ms
Used 157 ms
Used 250 ms
Used 359 ms
Used 485 ms
Used 610 ms
Used 781 ms
Used 969 ms
Used 1156 ms
Used 1422 ms
Used 1610 ms
Caching charts won't do anything here, as I am not changing the data, only the visibility.

Re: Bug when setting series visibility in Silverlight

Posted: Fri Sep 09, 2011 3:29 pm
by 10050769
Hello PCCUser,

You are right. We can reproduce your problem and we consider it as a bug with number [TW24015733]. We will try to fix it for next maintenance releases of TeeChartSilverlight.

Thanks,

Re: Bug when setting series visibility in Silverlight

Posted: Wed Dec 21, 2011 1:34 pm
by 15661118
Hello again,

I just installed the October release. I ran the exact same experiment and I got the same result, so the bug is still there. It has been several months now, and the bug is pretty severe (you cannot hide/show a series more than about 5 times or the whole application turns unusably slow in some cases). Can someone shed a little light on what is happening with this bug? When can I expect it to be fixed, and is there a workaround?

Re: Bug when setting series visibility in Silverlight

Posted: Thu Dec 22, 2011 10:58 am
by 10050769
Hello pcc_user,

After doing many test we have arrived a conclusion that the bug with number [TW24015733] it isn't a bug. Because, it is not a problem of memory leak is a problem of performance in the moment of repaints the chart, so is decreased its speed when you repaint several times in a short period of time. It is behaviour of TeeChartSilverlight known for us. Behaviour is caused for its internal design and whether adds that Silverlight is slower when repainting, we get instable results and are difficult to solve for us, but we will continue to work to achieve improve the performance of TeeChartSilverlight to next releases of TeeChartFor .Net. At the moment, the solution is give more time to paint the Chart, because it may do the repaint more stable.

Thanks,

Re: Bug when setting series visibility in Silverlight

Posted: Thu Dec 22, 2011 12:48 pm
by 15661118
I fail to see how this can be categorized as anything but a bug. Fine, so it is not a memory leak, but it still a bug. A behaviour that makes the chart repaint time go from ~10ms to ~10s after ~20 repaints is, well, buggy. I cannot see why any design desition could have introduced this strange behaviour - after all, there is no change in the data, chart settings, labels, marks or anything, only a repaint method call.

So if every 10 seconds you update a chart that used 10ms to repaint the first time, then after 3-4 minutes the application is 100% occipied with painting the chart, and the whole application is effectively broken. Again, I fail to see how this qualifies as a behaviour as opposed to a bug.

I would appreciate openness on this issue, as it could make our application more or less unusable without a hack/workaround. Have you done any profiling to see what it is that the chart is doing with all this time it is using, and why this is increasing after every repaint? Do you have any expectations on when this will be fixed? Could you update this thread as improvements are made? Is there a specific set of circumstances that this shows up in?

Thank you

Re: Bug when setting series visibility in Silverlight

Posted: Tue Dec 27, 2011 10:10 am
by 10050769
Hello pcc_user,

Sorry for the delay. How I explained previously, we doesn't consider this bug as a memory leak bug, but, this doesn't mean that we don't consider this problem as a problem and we will continue to work to achieve improve the performance of TeeChartSilverlight to next releases of TeeChartFor .Net to try to solve the problem.

Thanks,