PDA

View Full Version : Stylesheets affect performance



fredrikn
2nd February 2011, 10:31
Hi,
I have an application that I give a custom look with stylesheets. However the performance was really bad, and it turned out to be the use of stylesheets that caused the problems. When removing the stylesheets the performance was much better. So far the UI is really simple, just four stacked widgets and a few frames and buttons. The stylesheets are also very simple.

Example:
In each stacked widget I have one of these frames.


QFrame inner_frame1 = new QFrame(this);
inner_frame1->setGeometry(10, 10, 1242, 625);
inner_frame1->setStyleSheet(tr("QFrame { border: 2px solid white; border-radius: 20px; } "));

QFrame inner_frame2 = new QFrame(this);
inner_frame2->setGeometry(10, 10, 242, 125);
inner_frame2->setStyleSheet(tr("QFrame { border: 2px solid white; border-radius: 20px; } "));

QFrame inner_frame3 = new QFrame(this);
inner_frame3->setGeometry(10, 10, 1242, 625);

Changing to the widget with inner_frame1 is much slower than changing to the other two. The combination of a StyleSheet and a bigger area affect performance. I have tried other types of widgets, such as QLabel, with the same result.


Does anyone know:
Is this a known problem and are there any ways to avoid it?

Does the use of stylesheets require much more resources? The performance problems are mainly seen when I run on a computer on module which has a little limited resources.

Thanks,
Fredrik

high_flyer
2nd February 2011, 11:05
Yes, style sheets loading is rather slow from my experience.
But, it should not be done continuously in repeating code, rather, a stylesheet should be loaded once per widget.
If you load it only once, then performance is not an issue again.

fredrikn
2nd February 2011, 11:19
The loading of the stylesheets are only done in the constructors of the widgets. Also, it is the same if I set only one stylesheet for the entire application.

high_flyer
2nd February 2011, 11:28
Changing to the widget with inner_frame1 is much slower than changing to the other two.
Since your frame2 and frame1 have basically the same stylesheet, it can't be that the difference is rooted in the stylesheet.
It probably has to do with some other logic in your application that happens when you chage between frames.

If you take the style sheet out, do all frames need the same time?

fredrikn
2nd February 2011, 11:53
If I remove the stylesheet all the frames need the same time. (at least are really quick) That is what is done for inner_frame3.

In a little more advanced UI, the performance is improved significantly by just removing the stylesheet for graphically big objects.

high_flyer
2nd February 2011, 12:17
In a little more advanced UI, the performance is improved significantly by just removing the stylesheet for graphically big objects.
I can confirm as I said, from experience, that there is a (GUI refresh/draw) performance hit when using style sheets on complex GUI's.
But since it was a performance hit that was not disturbing, and since it only had to do with GUI painting, it didn't disturbed me to the point I had to investigate further.
To some extent I think it has to do as well with - if for example you are using a lot of images, and possibly large images (not to be seen in your example, I am talking in general).
Maybe someone who looked at it in more depth can comment as well.

KjellKod
11th August 2011, 23:27
It was some time ago but it could be worth mentioning that the performance problems reported above were finally resolved. On Linux machines (at least) and Intel Atom with integrated graphics chip there is some issues with how Qt are doing calls to the graphic card.

According to Intel low graphics performance with extremely high X cpu usage for even simple stuff is due how
Qt approximates a sine wave using the native X calls. This is highly inefficient and resulting in a multitude of extra calls into the Intel driver for creating/deleting pixmaps and drawing trapezoids.

Either way the solution was easy, using raster graphics engine instead of the default one removes this barrier. I've blogged about it a long time ago - you can read about it (see at the end) at
http://kjellkod.wordpress.com/2011/05/22/moving-to-qt5-will-that-remove-qts-performance-issues-on-linux/

cplus
12th August 2011, 11:00
I test this on Windows7 and Qt4.5.2, and it has no performance issue.

I use many stylesheets on my applications, they all don't have this problem.

KjellKod
12th August 2011, 13:57
@cplus, please read the blog I linked too (http://kjellkod.wordpress.com/2011/05/22/moving-to-qt5-will-that-remove-qts-performance-issues-on-linux/).

The issue is not with stylesheets itself, we just managed to trigger a dysfunctional *issue* in the interaction between Intel Atoms integrated graphic chip (+ driver) and how Qt manages graphic in its default graphics engine.

On another PC with a different chipset architecture you wouldn't see this at all! The best way to test if you have this issue is to use the "concentriccircles" or a modified version of it (again: read the blog),... with raster as graphicsengine and with the default as graphics engine and compare the result.

If there's an issue, the difference in efficiency is huge