QCustomPlot employs various techniques like adaptive sampling and text object caching in order to cut down the time required to replot. However, some features like complex translucent fills and thick lines can still cause a significant slow down. If you notice this in your application, here are some hints on how to increase replot performance.
By far the most time is spent in the drawing functions, specifically the drawing of high density graphs and other plottables. For maximum performance, consider the following points:
- Especially if you are using complex fills under/between graphs, thick lines, translucent colors: enable QCustomPlot's OpenGL hardware accelerated rendering via QCustomPlot::setOpenGl. For details how to correctly enable OpenGL acceleration, see the documentation there. OpenGL acceleration is available for all Qt versions that are supported by QCustomPlot, and the respective backend is chosen appropriately.
For Qt versions before 5.0, an alternative to QCustomPlot's own OpenGL acceleration is to supply "-graphicssystem opengl" as command line argument or calling QApplication::setGraphicsSystem("opengl")
before creating the QApplication object. This enables application wide OpenGL acceleration.
Note that with OpenGL acceleration, the maximum frame rate might be constrained by the vertical sync frequency of your monitor (VSync can be disabled in the graphics card driver configuration). So for simple plots (where the potential framerate is far above 60 frames per second), OpenGL acceleration might achieve numerically lower frame rates than the default software renderer, because it is not capped at the VSync frequency.
- Avoid lines with a pen width greater than one. This is especially relevant with the default software renderer, less so with OpenGL acceleration.
- Avoid complex fills, e.g. channel fills between graphs with thousands of points. This is especially relevant with the default software renderer, less so with OpenGL acceleration.
- If you often need to call a full QCustomPlot::replot only because a non-complex object (e.g. an item) has changed while having relatively static but complex graphs in the plot, consider placing the regularly changing objects onto an own layer and setting its mode (QCPLayer::setMode) to QCPLayer::lmBuffered. This makes QCustomPlot allocate a dedicated paint buffer for this layer, and allows it to be replotted individually with QCPLayer::replot, independent of the other layers containing the potentially complex and slow graphs. See the documentation of the respective methods for details.
- Qt4 only: Use Qt 4.8 or newer. Performance has doubled or tripled with respect to Qt 4.7. However, QPainter was broken and drawing pixel precise elements like scatters doesn't look as good as with Qt 4.7. So it's a performance vs. plot quality tradeoff when switching to Qt 4.8. QCustomPlot internally tries to work around the worst glitches of this kind.
- To increase responsiveness during range dragging, consider setting QCustomPlot::setNoAntialiasingOnDrag to true. This is only relevant if using the default software renderer. (OpenGL antialiasing can't be toggled on-the-fly and would require an expensive reallocation of the sample buffer.)
- Qt4 only: On X11 (GNU/Linux), avoid the slow native drawing system, use raster by supplying "-graphicssystem raster" as command line argument or calling
QApplication::setGraphicsSystem("raster")
before creating the QApplication object.
- Avoid any kind of alpha (transparency) colors, especially in fills.
- As a last resort, try to reduce the number of data points that are in the visible key range at any given moment, e.g. by limiting the maximum key range span (see the QCPAxis::rangeChanged signal). QCustomPlot can optimize away millions of off-screen points very efficiently.