Results 1 to 9 of 9

Thread: Stylesheets affect performance

  1. #1
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Stylesheets affect performance

    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.

    Qt Code:
    1. QFrame inner_frame1 = new QFrame(this);
    2. inner_frame1->setGeometry(10, 10, 1242, 625);
    3. inner_frame1->setStyleSheet(tr("QFrame { border: 2px solid white; border-radius: 20px; } "));
    4.  
    5. QFrame inner_frame2 = new QFrame(this);
    6. inner_frame2->setGeometry(10, 10, 242, 125);
    7. inner_frame2->setStyleSheet(tr("QFrame { border: 2px solid white; border-radius: 20px; } "));
    8.  
    9. QFrame inner_frame3 = new QFrame(this);
    10. inner_frame3->setGeometry(10, 10, 1242, 625);
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by wysota; 2nd February 2011 at 11:12. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Stylesheets affect performance

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Stylesheets affect performance

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Stylesheets affect performance

    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?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Stylesheets affect performance

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Stylesheets affect performance

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Jan 2006
    Location
    Scandinavia
    Posts
    62
    Thanks
    5
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Stylesheets affect performance

    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 Code:
    1. 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.
    To copy to clipboard, switch view to plain text mode 

    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/0...sues-on-linux/

  8. #8
    Join Date
    Aug 2011
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Stylesheets affect performance

    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.

  9. #9
    Join Date
    Jan 2006
    Location
    Scandinavia
    Posts
    62
    Thanks
    5
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Stylesheets affect performance

    @cplus, please read the blog I linked too (http://kjellkod.wordpress.com/2011/0...sues-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

Similar Threads

  1. StyleSheets: border-image performance
    By GuS in forum Qt Programming
    Replies: 3
    Last Post: 15th May 2013, 12:42
  2. Stylesheets Performance
    By Steven in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2011, 11:34
  3. Stylesheets
    By FuryCradle in forum Newbie
    Replies: 2
    Last Post: 26th September 2009, 21:34
  4. stylesheets with RGB
    By tommy in forum Qt Programming
    Replies: 4
    Last Post: 13th December 2007, 01:02
  5. Replies: 3
    Last Post: 30th April 2006, 19:22

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.