Skip to content

How to speed up rendering of many plots #1127

@EFeru

Description

@EFeru

ScottPlot 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 Using Vector Graphics instead of Bitmap graphics #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:

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;
    //});
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions