Performance issues with simple test on Qt5 vs Qt4 on ARM device without GPU



  • Hello!

    I've been running some simple tests on Qt5.4.1 and Qt4.8.6 on an ARM processor without a GPU (so on Qt5, the program uses linuxfb, and on Qt4, it uses the QWS). I expected Qt5 to be faster because it won't have the overhead of the QWS, but my tests show otherwise.

    Here is what I used to test it:

    //lines.h
    #pragma once
    #include <QWidget>
    class Lines : public QWidget
    {
    	Q_OBJECT
    	public:
    		Lines(QWidget *parent = 0);
    
    	public slots:
    		void animate();	
    
    	protected:
    		void paintEvent(QPaintEvent *event);
    		void drawLines(QPainter *qp);
    		int frameCounter;
    };
    
    //lines.cpp
    #include "lines.h"
    #include <QPainter>
    #include <stdio.h>
    #include <QTimer>
    #include <QTime>
    
    #define NUMSHAPES 1000
    QTime t;
    
    Lines::Lines(QWidget *parent) : QWidget(parent) 
    {
    	frameCounter = 0;
    
    	QTimer *timer = new QTimer(this);
    	connect(timer, SIGNAL(timeout()), this, SLOT(animate()));
    
    	#ifndef QT4USED
    	timer->setTimerType(Qt::PreciseTimer);
    	#endif
    
    	timer->start(10);	
    	t.start();
    }
    
    void Lines::paintEvent(QPaintEvent *e) 
    { 
    	Q_UNUSED(e);
    	QPainter qp(this);
    	drawLines(&qp);
    
    	double a = t.restart();	  	
    	fprintf(stderr,"time: %lf fps: %lf\n", a, 1000.0/a);
    }	
    
    void Lines::animate() 
    {
    	frameCounter++;
    	//repaint();
    	update();	
    }
    
    void Lines::drawLines(QPainter *qp) 
    { 
    	for ( int c = 0; c < NUMSHAPES; c++ )
    	{		
    		QPen pen(Qt::red, 1, Qt::SolidLine);  
    		qp->setPen(pen);
    		int xbegin, xend, ybegin, yend ;
    		xbegin = xend = frameCounter*10;
    		ybegin = 0;
    		yend= 250;
    		
    		qp->drawLine( xbegin, ybegin, xend, yend );
    	}
    }
    
    
    //main.cpp
    #include "lines.h"
    #include <QApplication>
    #include <stdio.h>
    int main(int argc, char *argv[]) 
    {
    	QApplication app(argc, argv);
    	Lines window;
    
    	window.resize(640, 480);
    	window.setWindowTitle("Lines");
    	window.show();
    
    	return app.exec();
    }
    

    In summary, the code starts a timer with an interval of 10 msecs, and calls update() on the Lines widget. The widget itself paints a 1000 drawLines() every frame, and then outputs the time taken between each frame to stderr.

    This program causes 100% cpu usage on both Qt5 and Qt4, but Qt5 takes an average of 55 msecs per frame, while Qt4 takes 50. While this isn't too different, does anyone have a clue why Qt5 is actually slower? Shouldn't it be at least as fast because the QWS is out of the picture?

    But the bigger problem is the CPU usage when the widget paints a 100 lines every frame instead of 1000. On Qt5, it paints a frame every 13 milliseconds, and the CPU usage is still 100%, but on Qt4, it paints a frame every 10 milliseconds and the CPU usage is about 85%. Any ideas why Qt5 seems to be underperforming?


  • Moderators

    Interesting. Could you try running both "versions" through callgrind or some other profiling tool? Maybe that will help somewhat.

    The only code difference you add here (between Qt 4 and 5) is timer precision - but that should not make much difference (please check, though).

    The only thing I can think of right now is that QPainter's handling of thin lines and antialiasing has been slightly changed when going from Qt 4 to Qt 5. So perhaps Qt 5 is using more time to properly draw the line. Or the reason could be completely different: maybe linuxfb painting is slower on your device?



  • @sierdzio Thanks a lot for the reply!
    I'll try running it through a profiler, and looking through the QPainter source. Out of curiosity, I also tried painting absolutely nothing in the paint event, so that all the timer will do is call update() every 10 milliseconds. In Qt4, that gave me a 100% idle cpu, but in Qt5, it was about 15% idle. So I changed the update() call to a repaint() call, and saw that the Qt4 idle time dropped to 33%, but the Qt5 one had no change(still 15% idle)...Were there any major changes to how Qt updates/repaints between 4 and 5?


  • Moderators

    Hm. You would have to ask Qt developers (on IRC, or development mailing list) to get a definite answer. In Qt4->5 transition, the whole painting architecture was changed, so it is understandable there are differences in performance. What is not so good is that (from your data, and sporadic reports I see in other places) the performance of Qt5 is worse instead of better.



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.