From 65794ebdb5adff23dad198158d5bf0b91c280699 Mon Sep 17 00:00:00 2001 From: Allan Bazinet Date: Mon, 2 Dec 2024 09:44:36 -0800 Subject: [PATCH] Add Qwt drawPolyline() performance workaround --- plotter.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/plotter.cpp b/plotter.cpp index a7662f5d..b9be71ce 100644 --- a/plotter.cpp +++ b/plotter.cpp @@ -26,6 +26,12 @@ namespace constexpr qreal RDP_EPSILON = 2.0; + // The Qt Raster engine seems to have terrible performance when + // drawing large polylines; the size at which we should split + // drawing into smaller lines. + + constexpr qsizetype POLYLINE_SIZE = 6; + // Resize debounce interval, in milliseconds; adjust to taste. constexpr auto RESIZE_DEBOUNCE_INTERVAL = 100; @@ -454,11 +460,22 @@ CPlotter::drawData(WF::SWide swide) } // Draw the spectrum line, reducing the resulting points prior to - // drawing them, but keeping the collection capacity. + // drawing them, but keeping the collection capacity. We also work + // around what seems to be a performance bug in all versions of Qt + // up to and including 6.8, when drawing large polylines; this was + // culled from the Qwt library's workaround for the issue. Doubles + // overall program performance, pretty much. m_points.erase(rdp(m_points), m_points.end()); p.setRenderHint(QPainter::Antialiasing); - p.drawPolyline(m_points); + + for (qsizetype i = 0; + i < m_points.size(); + i += POLYLINE_SIZE) + { + p.drawPolyline(m_points.data() + i, qMin(POLYLINE_SIZE + 1, + m_points.size() - i)); + } } // Save the data against a potential replot requirement.