xyzzer / WinRTXamlToolkit

WinRT XAML Toolkit
Other
282 stars 67 forks source link

Windows UWP: Chart-Rendering slow/blocking UI #23

Closed schrooom closed 8 years ago

schrooom commented 8 years ago

I'm developing an app for Windows 10 Mobile and need to draw a chart within that app. The chart is created via XAML, only the math needed & adding those calculated values to the chart is done via C#.

The problem is that the rendering of the chart needs +-15 seconds (on Windows 10 Mobile) and within that time it blocks the UI, which is quite blocking a fluent user experience...

Corresponding question on StackOverflow

xyzzer commented 8 years ago

How many data points in the chart? Do you just draw it once or does it update live?

On Wed, Mar 16, 2016 at 11:02 AM, jerry1621 notifications@github.com wrote:

I'm developing an app for Windows 10 Mobile and need to draw a chart within that app. The chart is created via XAML, only the math needed & adding those calculated values to the chart is done via C#.

The problem is that the rendering of the chart needs +-15 seconds (on Windows 10 Mobile) and within that time it blocks the UI, which is quite blocking a fluent user experience...

(Corresponding question on StackOverflow: http://stackoverflow.com/questions/35745428/windows-uwp-winrtxamltoolkit-controls-datavisualization-chart-rendering-slow http://url)

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/xyzzer/WinRTXamlToolkit/issues/23

schrooom commented 8 years ago

@xyzzer Thanks for your quick response! The chart gets 512 data points (x2, because it has one AreaSeries and one LineSeries) and I'm only drawing it once.

xyzzer commented 8 years ago

That's a lot of data points. XAML really performs well up to about 500-1000 elements and with 1024 data points you might be getting thousands of data points easily. You'll need to either reduce the number of points or switch to immediate-mode rendering (D2D).

On Wed, Mar 16, 2016 at 11:05 AM, jerry1621 notifications@github.com wrote:

@xyzzer https://github.com/xyzzer Thanks for your quick response! The gets 512 data points (x2, because it has one AreaSeries and one LineSeries) and I'm only drawing it once.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/xyzzer/WinRTXamlToolkit/issues/23#issuecomment-197461466

schrooom commented 8 years ago

@xyzzer Unfortunately the problem persists with only one series or 256 data points per series...

jorticus commented 8 years ago

I've also found charting to be really really slow in UWP, and I only have ~200 data points. Profiling seems to suggest that the garbage collector is collecting a huge number of references during DataPointSeries::Refresh() (of what I'm not sure), introducing a delay of 500 - 1500ms on my PC (much longer on phone). If I force a GC before the Refresh(), then it only takes ~100ms, but the GC collection blocks for the rest of the time.

My theory is that the CLR<>WinRT interop stuff is creating a lot of references (DataPoint is a CLR class, while the Bindings are WinRT), so perhaps converting the library to a Windows Runtime Component instead of a Class Library would solve it (easier said than done!)

xyzzer commented 8 years ago

It's a possibility. Also possible that there's simply a bug in the library that causes that stall to happen. Most likely though - I think the library was designed to enable pretty-looking charts in WPF and then Silverlight that would follow XAML design patterns - allowing restyling, templating and extensibility, but high performance was never the top priority. Then I inherited the problem when I ported it from Silverlight Toolkit. I would try reducing the number of data points to well below 100. 256 and 512 are still the same order of magnitude, so don't expect miracles from a 50% reduction of data size. I feel it should work OK with 25 data points and if what you want is a high resolution, high performance chart - use DirectX to draw it or check out some commercial charting controls.

xyzzer commented 8 years ago

Check this as a sample: https://github.com/xyzzer/Win2DChartSample