Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-8151

Performance optimization when using SVG graphics with QIcon (QSvgIconEngine)

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Fixed
    • P3: Somewhat important
    • 6.8.0 FF
    • 4.5.3, 4.6.0
    • SVG Support
    • None
    • 60061f679 (dev)

    Description

      Please add in file
      ($QTDIR)\src\plugins\iconengines\svgiconengine\qsvgiconengine.cpp
      in the method QSvgIconEngine::addFile()
      at line 219 the following condition

       
      if (d->svgFiles.value(d->hashKey(mode, state)) != abs)
      {
          QSvgRenderer renderer(abs);
          if (renderer.isValid())
          {
              d->stepSerialNum();
              d->svgFiles.insert(d->hashKey(mode, state), abs);
          }
      }
      

      This condition helps avoiding QSvgRenderer from needlessly loading and parsing a SVG document, if it has already been inserted to the internal hash.
      In practice this happens very often because QSvgIconEngine::addFile() gets called always twice when using icons in this way QIcon(":/icons/IconA.svg"). The first call is done by QSvgIconPlugin::create() [src\plugins\iconengines\svgiconengine\main.cpp, line 75].
      The second call is done by QIcon::addFile() [src\gui\image\qicon.cpp] after the QSvgIconEngine has been created.

      When using a large amount of QIcons with SVGs in a UI this helps to speed up the application.

      (I even went further and wrote my own new svg iconengine that uses a QCache of QSvgRenderer similar to QPixmapCache to preferably have each svg parsed only once regardless of the amount of rendered icon sizes.)

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-8151
          # Subject Branch Project Status CR V

          Activity

            People

              Unassigned Unassigned
              jenssch2 Jens Schmeling
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes