Results 1 to 4 of 4

Thread: Significant performance issue with high dpi

  1. #1
    Join Date
    Oct 2019
    Posts
    23
    Qt products
    Qt5
    Platforms
    Windows

    Default Significant performance issue with high dpi

    Hello,

    I have a simple test program that plots 10 curves with 288 points each:

    .h
    Qt Code:
    1. class MyPlot : public QwtPlot
    2. {
    3. public:
    4. void drawCanvas(QPainter* painter) override
    5. {
    6. const auto start = std::chrono::system_clock::now();
    7. QwtPlot::drawCanvas(painter);
    8. const auto end = std::chrono::system_clock::now();
    9. const auto dt = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
    10. qDebug().nospace() << "dt = " << dt.count() << "ms";
    11. }
    12. };
    13.  
    14.  
    15. class QwtPlotClient : public QDialog
    16. {
    17. Q_OBJECT
    18.  
    19. public:
    20. QwtPlotClient(QWidget* parent = nullptr);
    21.  
    22. private:
    23. Ui::QwtPlotClientClass m_ui;
    24. MyPlot* m_plot = nullptr;
    25.  
    26. };
    To copy to clipboard, switch view to plain text mode 

    .cpp
    Qt Code:
    1. namespace
    2. {
    3. std::vector<QVector<QPointF>> createPlotData(int curveCount = 10, int pointsPerCurve = 288)
    4. {
    5. std::vector<QVector<QPointF>> result;
    6. std::default_random_engine engine(std::random_device{}());
    7. std::uniform_real_distribution<double> distribution(-100.0, 100.0);
    8. for (int curveIndex = 0; curveIndex < curveCount; curveIndex++)
    9. {
    10. QVector<QPointF> curvePoints;
    11. double x = 0.0;
    12. for (int point = 0; point < pointsPerCurve; point++)
    13. {
    14. curvePoints << QPointF(x, distribution(engine));
    15. x += 2.0;
    16. }
    17. result.push_back(curvePoints);
    18. }
    19. return result;
    20. }
    21. }
    22.  
    23. QwtPlotClient::QwtPlotClient(QWidget* parent)
    24. : QDialog(parent),
    25. m_plot(new MyPlot)
    26. {
    27. m_ui.setupUi(this);
    28. m_ui.plotFrame->layout()->addWidget(m_plot);
    29.  
    30. const auto curvePointsList = createPlotData();
    31. for (const auto& curvePoints : curvePointsList)
    32. {
    33. auto* curve = new QwtPlotCurve();
    34. curve->setSamples(curvePoints);
    35. curve->attach(m_plot);
    36. }
    37. }
    To copy to clipboard, switch view to plain text mode 

    In my main.cpp I define if the program uses high dpi settings or not:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. // Comment the following 4 lines for NOT using high dpi settings
    4. QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    5. QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round);
    6. QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
    7. QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
    8.  
    9. QApplication a(argc, argv);
    10. QwtPlotClient w;
    11. w.show();
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    As you can see I measure the time that the qwt plot needs for drawing the canvas (see MyPlot::drawCanvas). The results are (on my computer, you probably will have different absolute values):

    High dpi settings off: ~25ms (for Debug) / ~10ms (for Release)
    High dpi settings on: ~800ms ms (for Debug) / ~570ms (for Release)

    I tested this with Qt 5.14.0 and Qwt 6.2.1. (I also tested with Qwt 6.2.0 and the numbers for high dpi settings on are even a bit larger.)

    Is there anything I can do? Or do you plan to "fix" this in the near future?

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,318
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Significant performance issue with high dpi

    Qwt can do some algorithmic workarounds to avoid doing unnecessary stuff, but in the end it is Qt that is doing the rendering. So I'm afraid there is not much Qwt can do here.

    In case you are on X11 I recommend to use the hardware accelerated X11 paint engine. ( export QT_XCB_NATIVE_PAINTING=1 ) instead of the homebrew raster paint engine, that is enabled as default.
    On Windows you can go with OpenGL, but according to the docs it does not seem to support AA_EnableHighDpiScaling.

    By the way: did you check which of the flags is hurting most ?

    Uwe

  3. #3
    Join Date
    Oct 2019
    Posts
    23
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Significant performance issue with high dpi

    The flag that hurts most is Qt::AA_EnableHighDpiScaling. The other three flags seem to have almost no effect on the performance at all.

    Thank you for your reply and explanation. Since we plan to migrate to Qt6.5 in the near future and our Qt expert mentiones that a lot of improvements were made for high dpi in Qt6, we hope that this will mitigate the bad render performance for qwt, too.

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,318
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Significant performance issue with high dpi

    Quote Originally Posted by mwh View Post
    we hope that this will mitigate the bad render performance.
    I would be surprised if this would be the case. In the end the raster paint engine has to fill significantly more pixels, where the majority will be found somehow by interpolating - what is simply way more expensive.
    IMHO your options are not to enable AA_EnableHighDpiScaling or to avoid the raster paint engine.

    HTH,
    Uwe

Similar Threads

  1. high performance database for QT
    By bandito in forum General Programming
    Replies: 1
    Last Post: 3rd June 2016, 09:16
  2. Replies: 8
    Last Post: 9th January 2015, 21:08
  3. High performance Http Server
    By niko in forum Qt Programming
    Replies: 1
    Last Post: 11th December 2009, 09:58
  4. High performance large file reading on OSX
    By mikeee7 in forum Qt Programming
    Replies: 2
    Last Post: 15th October 2009, 15:18
  5. Replies: 1
    Last Post: 9th June 2008, 21:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.