Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

QPainter MSVC 2019 debug build runs 7 times slower than release build?



  • Hello,

    last months I was programming on Linux. Back on Windows 10 64bit I was confused because the MSVC 2019 debug build of my Qt 6.0 QPainter application runs 7-8 times slower than release builds. This only gets a tiny bit better the more I go back in Qt 5.15.x versions. It makes no difference if Qt Creator 4.13.3 or MS Visual Studio 2019 (latest) is used.

    I can't remember to have seen this slow debug builds before. But don't know if that's normal or if MS Visual Studio 2019 or Windows 10 updates might be the reason for this slow debug build performance.

    The following QPainter animation finishes:
    On Linux KDE Plasma: debug build 12.22 seconds, release build 12.03 seconds
    On Windows 10 64bit: debug build 70.14 seconds, release build 8.96 seconds

    Hardware:
    Intel i7-8700 CPU with buildin Intel UHD 630 Graphics

    #include <QApplication>
    #include <QWidget>
    #include <QPainter>
    #include <QElapsedTimer>
    
    class Widget : public QWidget
    {
    public:
        Widget();
    
    protected:
        void timerEvent(QTimerEvent*);
        void paintEvent(QPaintEvent*);
    
    private:
        QElapsedTimer elapsedTimer;
        int timerId;
        int elapsedTime = 0;
        bool isFinished = false;
        double i=0.0, x=40.0, y=0.0, y2=30.0;
        QPen Pen = QPen(QColor(0,0,0), 8);
    };
    
    Widget::Widget()
    {
        setAutoFillBackground(true);
        setPalette(Qt::white);
    
        timerId = startTimer(1);
        elapsedTimer.start();
    }
    
    void Widget::timerEvent(QTimerEvent*)
    {
        update();
    }
    
    void Widget::paintEvent(QPaintEvent*)
    {
        QPainter painter(this);
        painter.beginNativePainting();
    
        if (i >= 0 && i < 3770) {
            y = 30.0;
            painter.setPen(Pen);
            painter.drawLine(x-20.0, y,       x+76.0, y);
            painter.drawLine(x-20.0, y+570.0, x+76.0, y+570.0);
    
            for (int j=0; j < 550; j=j+30) {
                painter.drawEllipse(x-40.0, y2+j, 30.0, 30.0);
                painter.drawEllipse(x+69.0, y2+j, 30.0, 30.0);
            }
    
            painter.setFont(QFont("Arial", 14));
            painter.drawText(x, y += 20.0, "MSVC");
            painter.drawText(x, y += 20.0, " 2019");
            painter.drawText(x, y += 20.0, "debug");
            painter.drawText(x, y += 20.0, " mode ");
            painter.drawText(x, y += 20.0, " builds");
            painter.drawText(x, y += 20.0, "  run");
            painter.drawText(x, y += 20.0, "  7-8");
            painter.drawText(x, y += 20.0, " times");
            painter.drawText(x, y += 20.0, "slower");
            painter.drawText(x, y += 20.0, " than");
            painter.drawText(x, y += 20.0, " relase ");
            painter.drawText(x, y += 20.0, " mode");
            painter.drawText(x, y += 20.0, " builds");
            painter.drawText(x, y += 20.0, " using");
            painter.drawText(x, y += 20.0, " Qt 6.0");
            painter.drawText(x, y += 20.0, "");
            painter.drawText(x, y += 20.0, " Prior");
            painter.drawText(x, y += 20.0, "  Qt");
            painter.drawText(x, y += 20.0, "version");
            painter.drawText(x, y += 20.0, "  like");
            painter.drawText(x, y += 20.0, "   Qt");
            painter.drawText(x, y += 20.0, "5.15.2");
            painter.drawText(x, y += 20.0, "  run");
            painter.drawText(x, y += 20.0, "  only");
            painter.drawText(x, y += 20.0, " little");
            painter.drawText(x, y += 20.0, " faster");
            painter.drawText(x, y += 20.0, "");
            painter.drawText(x, y += 20.0, "  Ok?");
            x = x + 0.2;
    
            elapsedTime = elapsedTimer.elapsed();
        }
        else {
            isFinished = true;
        }
        i++;
    
        if (isFinished) {
            painter.setFont(QFont("Arial", 14, QFont::Bold));
            painter.drawText(QPoint(320, 280), "Elapsed time: " + QString::number(elapsedTime/1000.0) + QString(" seconds"));
        }
    }
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        Widget widget;
        widget.resize(900,640);
        widget.show();
        return app.exec();
    }
    

    Is there something wrong with my MSVC 2019 compiler debug setup? Or is it normal that 5.15.x and Qt 6.0 debug builds run that slow on Windows?



  • You could check the code you call for costly assert statements. In one case, this was the reason debug code ran by factors slower than release code.

    It doesn't explain the differences between MSVC and GCC, though



  • Hello Asperamanca,
    thank you for answering. But I don't understand your notice. The test snipped I provided above doesn't contain "assert" statements.

    Meanwhile I did a complete reinstall of MS Visual Studio 2019 community. But the slow debug build performance of above QPainter test animation code remains the same.



  • @mireiner Many Qt functions do use asserts internally. Sometimes this can severely slow down code in debug builds.


Log in to reply