PDA

View Full Version : Slow Graphics since Qt 5.6.0



mireiner
16th June 2016, 21:29
Hi there,

the problem:
The graphic animations of the same Qt application are running on Qt 5.4.2, Qt 5.5.0 and Qt 5.5.1 just fine. But on Qt 5.6.0, Qt 5.6.1 and Qt 5.7.0 at minimum 100% slower. No matter if MinGW 32 bit or Microsoft 32 or 64 bit compiler is used.

Setup:
Processor: Intel Core 2 Duo E8400 @ 3.00GHz
RAM: 8GB
Graphicscard: ATI Radeon HD 3600 - Directx 10.1 (non gamer card)
Operating System: Windows 10 64 bit (no enviroment variable set for Qt)
IDE: Qt Creator
Qt Windows Desktop Application 32 and 64bit.
Graphic Animations run on QWidget with QPainter and 100x drawText() and 400x drawLine() functions.
Animations are started with mouse click and hold on QPushbutton with autorepeat=true and "autorepeatinterval"=0

I tried to isolate the problem to a specific part of the application without success. If QPainter::drawText() is disabled in the full application, then it seams the speed is there again. But if I program a small test application with massiv use of QPainter::drawText() only, there is no slow down between the different Qt versions.

It's hard for me to understand on what graphics driver my Qt application is running on Windows 10 (ANGLE or OpenGL?). So eventually there might be the problem. Because I did not change anything in my Qt application when testing the obove mentioned Qt versions. Should I have done that? For example set an Windows enviroment variable oder an entry in project file (*.pro)?

Does anybody know what the problem might be, or provide tips how to find the issue?

wysota
17th June 2016, 00:23
Try profiling your app to see where the bottleneck is.

mireiner
17th June 2016, 11:19
Hi wysota,

I found the bug. It's in QPainter:drawText() but only in combination with QPainter::setFont(). The following code runs two tests. A Windows 10 desktop application build with Qt 5.4.2, Qt 5.5.0 and Qt 5.5.1 will execute both tests with the same speed in debug mode. But build with Qt 5.6.0, Qt 5.6.1 or Qt 5.7.0 Test2 takes about 9 times longer than Test1!



#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 elapsedTime1, elapsedTime2;
bool isFinished1, isFinished2, isFinished3;
int i, x1, x2, y1, y2;
};

Widget::Widget()
{
setAutoFillBackground(true);
setPalette(Qt::white);

timerId = startTimer(1);
elapsedTimer.start();

i=0; x1=0; x2=0;
isFinished1 = isFinished2 = isFinished3 = false;
}

void Widget::timerEvent(QTimerEvent*)
{
update();
}

void Widget::paintEvent(QPaintEvent*)
{
QPainter painter(this);

if (i > 0 && i < 800)
{
// 'Test1' runs about 9 times faster than 'Test2' on Qt 5.6.0, Qt 5.6.1 and Qt 5.7.0

y1 = 10;
painter.setFont(QFont("Arial", 14));
painter.drawText(x1, y1 += 30, "Test 1");
painter.drawText(x1, y1 += 30, "row 01");
painter.drawText(x1, y1 += 30, "row 02");
painter.drawText(x1, y1 += 30, "row 03");
painter.drawText(x1, y1 += 30, "row 04");
painter.drawText(x1, y1 += 30, "row 05");
painter.drawText(x1, y1 += 30, "row 06");
painter.drawText(x1, y1 += 30, "row 07");
painter.drawText(x1, y1 += 30, "row 08");
painter.drawText(x1, y1 += 30, "row 09");
painter.drawText(x1, y1 += 30, "row 10");
painter.drawText(x1, y1 += 30, "row 11");
painter.drawText(x1, y1 += 30, "row 12");
x1++;

elapsedTime1 = elapsedTimer.elapsed();
}
else if (i > 800 && i < 1600)
{
// 'Test2' takes about 9 times longer than 'Test1' on Qt 5.6.0, Qt 5.6.1 and Qt 5.7.0

isFinished1 = true;

y2 = 300;
painter.setFont(QFont("Arial", 14));
painter.drawText(x2, y2 += 30, "Test 2");
painter.setFont(QFont("Caladea", 14));
painter.drawText(x2, y2 += 30, "row 01");
painter.setFont(QFont("Tomaha", 14));
painter.drawText(x2, y2 += 30, "row 02");
painter.setFont(QFont("Consolas", 14));
painter.drawText(x2, y2 += 30, "row 03");
painter.setFont(QFont("Calibri", 14));
painter.drawText(x2, y2 += 30, "row 04");
painter.setFont(QFont("Impact", 14));
painter.drawText(x2, y2 += 30, "row 05");
painter.setFont(QFont("Courier New", 14));
painter.drawText(x2, y2 += 30, "row 06");
painter.setFont(QFont("Gorgia", 14));
painter.drawText(x2, y2 += 30, "row 07");
painter.setFont(QFont("Verdana", 14));
painter.drawText(x2, y2 += 30, "row 08");
painter.setFont(QFont("Times New Roman", 14));
painter.drawText(x2, y2 += 30, "row 09");
painter.setFont(QFont("Microsoft Sans Serif", 14));
painter.drawText(x2, y2 += 30, "row 10");
painter.setFont(QFont("Segoe UI", 14));
painter.drawText(x2, y2 += 30, "row 11");
painter.setFont(QFont("Trebuchet MS", 14));
painter.drawText(x2, y2 += 30, "row 12");
x2++;

elapsedTime2 = elapsedTimer.elapsed();
}
else if (i > 1600)
{
isFinished2 = true;
}
i++;

if (isFinished1)
{
painter.setFont(QFont("Arial", 12, QFont::Bold));
painter.drawText(QPoint(200, 150), "'Test1' elapsed time in seconds: " + QString::number(elapsedTime1/1000.0));
}
if (isFinished2)
{
painter.drawText(QPoint(200, 430), "'Test2' elapsed time in seconds: " + QString::number((elapsedTime2-elapsedTime1)/1000.0));
isFinished3 = true;
}
if (isFinished3)
{
painter.setFont(QFont("Arial", 11));
painter.drawText(QPoint(200, 620), "On Windows Desktop with Qt 5.4.2, Qt 5.5.0 and Qt 5.5.1 Test1 and Test2 are both equally fast.");
painter.drawText(QPoint(200, 650), "On Windows Desktop with Qt 5.6.0, Qt 5.6.1 and Qt 5.7.0 Test2 is approx 9 times slower than Test1 !");
painter.drawText(QPoint(200, 680), "No matter if compiled with MinGW 32bit or MSVC 32 or 64bit");
killTimer(timerId);
}
}

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Widget widget;
widget.showMaximized();
return app.exec();
}

Did you know how to report a bug report to the Qt developer team? Never did that before. Can you help me with this?

anda_skoa
17th June 2016, 13:43
Qt has an open bug tracker at https://bugreports.qt.io/secure/Dashboard.jspa

Cheers,
_

mireiner
17th June 2016, 14:56
Hi anda_skoa,

thanks for the link. So I reported this bug on the site you mentioned:
(QTBUG-54180) https://bugreports.qt.io/browse/QTBUG-54180?jql=text%20~%20%22QPainter%3A%3AdrawText%22

But the first reaction is a bit funny. It seams they didn't even test my short example code and write it's normal that this code runs so slow. Nevertheless I reported that all earlier Qt version prior v5.6.0 ran this code fast and only the newer Qt versions 5.6.0 and later got this massiv slow down with this example code. :confused:

anda_skoa
18th June 2016, 08:33
The developer probably focused too much on the title, which doesn't include that it become slower between versions.

I would recommend to post your numbers.
Instead of drawing the elapsed time write it to qDebug() or similar and paste edit the report to contian these for a good and a bad version.

Cheers,
_