How to speed up rendering of many plots
See original GitHub issueScottPlot Version: 4.1.16 Operating System: WIN10 Application Type: WinForms
Issue Description: In my application I create a list of plots that are linked. Basically I allow the user to create as many plots as he wants. The drawback is that with the increased number of plots and signals the interaction with the plots becomes slower and slower.
Questions: Do you have suggestions on what to do to speed up the rendering process? (compute in parallel, threads, use GPU, etc.)
Below is a snippet of the code that is excuted every time the use interracts with one of the plots. Works decent up to 4 plots and moderate number of signals (up to 10 signals/plot, and let’s say up to 10000 points/signal). However, above that I start to feel degradation of speed that affects user interraction.
Using Parallel.ForEach
doesn’t help much. Especially for the Vertical Lines dragged linked
I get strange delayed behavior if I use Parallel.ForEach
.
-
In the past I have used a graph tool that used the Arction engine. It was very fast, I must admit even, with many many plots. It is using DirectX in the background. Maybe we can learn from it.
-
Then I was triggered by Matlab, which I intensively use. Matlab uses OpenGL to render and it renders quite fast. Do you think OpenGL would increase rendering time in C#, see: https://github.com/dwmkerr/sharpgl If we could use it in ScottPlot, then 3D plots and surface plots will become possible too. What is your opinion on that? This topic is related to #1113
-
Or is there a posibility to use the GPU power in C# for rendering?
-
For me any option that helps to speed up the rendering of many plots is ok. Because only 20% of processing power is used at the moment on my laptop. So, I think we can do more to use the available resources to our advantage.
Other links that I found:
- https://github.com/sharpdx/SharpDX
- https://github.com/microsoft/Win2D
- https://www.reddit.com/r/csharp/comments/5uvyw9/what_can_i_use_for_basic_fast_2d_graphics/?utm_source=amp&utm_medium=&utm_content=post_body
For X Axes linked:
public static void OnAxesChanged(object sender, EventArgs e)
{
FormsPlot changedPlot = (FormsPlot)sender;
axisXMin = changedPlot.Plot.GetAxisLimits().XMin;
axisXMax = changedPlot.Plot.GetAxisLimits().XMax;
foreach (FormTimePlot tp in timePlot)
{
if (tp.formsPlot == changedPlot)
continue;
// Disable events briefly to avoid an infinite loop
tp.formsPlot.Configuration.AxesChangedEventEnabled = false;
tp.formsPlot.Plot.SetAxisLimits(xMin: axisXMin, xMax: axisXMax);
tp.formsPlot.Render();
tp.formsPlot.Configuration.AxesChangedEventEnabled = true;
}
//Parallel.ForEach (timePlot, tp =>
//{
// // Disable events briefly to avoid an infinite loop
// tp.formsPlot.Configuration.AxesChangedEventEnabled = false;
// tp.formsPlot.Plot.SetAxisLimits(xMin: axisXMin, xMax: axisXMax);
// tp.formsPlot.Render();
// tp.formsPlot.Configuration.AxesChangedEventEnabled = true;
//});
}
For Vertical Lines dragged linked:
public static void OnAxesDragged(object sender, EventArgs e)
{
VLine changed_Line = (VLine)sender;
vPosition = changed_Line.X;
foreach (FormTimePlot tp in timePlot)
{
if (tp.vLine == changed_Line)
continue;
tp.vLine.X = vPosition;
tp.formsPlot.Configuration.AxesChangedEventEnabled = false;
tp.formsPlot.RenderRequest();
tp.formsPlot.Configuration.AxesChangedEventEnabled = true;
}
//Parallel.ForEach(timePlot, tp =>
//{
// tp.vLine.X = vPosition;
// tp.formsPlot.Configuration.AxesChangedEventEnabled = false;
// tp.formsPlot.Render();
// tp.formsPlot.Configuration.AxesChangedEventEnabled = true;
//});
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
@EmanuelFeru a while back I did some experimentation with SkiaSharp and plotting and it was fantastic performance https://github.com/swharden/quickplot
The problem at that time was the build process was non-trivial (compared to System.Drawing which just seemed to work everywhere).
With #1036 and discussion emerging there this issue is on its way to being solved! I’ll close this issue for now, and hopefully tackle this around the time .NET 6 and
Microsoft.Maui.Graphics.Skia
is out of preview 👍I will do some more tries. For now I will close the topic. Thank you for your answers.