Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-63067 Performance and memory consumption improvements for QtQml
  3. QTBUG-64541

Avoid binding allocations for side-effect free property initializers

    XMLWordPrintable

Details

    Description

      We can observe that QML files are sometimes used to store settings / styling type of information. It acts like a JSON file but it can be used directly in bindings and is human readable and editable.

      For example Placements.qml:

      import QtQml 2.0
      QtObject {
          readonly property rect homeButtonPlacement: Qt.rect(0, 0, 20, 20)
          readonly property rect backButtonPlacement: Qt.rect(100, 100, 20, 20)
          ...
          readonly property var defaultColors: {
              "homeButton": "green",
              "backButton": "black",
          }
          ...
      }
      

      Often code like that is generated from an external source.

      At the moment when the QML engine loads such a QML file, we evaluate JS binding expressions for the Qt.rect(...) calls as well as for the object literal expressions.

      While there exists the option of considering making these two constructs built-in and detected at compile time, another more general optimization surfaces:

      If a binding expression does not depend on any other properties that might change (in engine terms: there are no captures registered after evaluation) and the evaluation result is assigned to a read-only property, then we can conclude that afterwards the value cannot change anymore. Therefore we can remove the binding object that was used for the initialization.

      This saves memory.

      On a large scale application this optimization saved up to 5% of all bindings on start-up (~9000 of ~180000). On Linux x86-64 one binding is approximately 144 bytes, so the savings are in the range of ~1.2 MB of heap, as well as reduced fragmentation.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            shausman Simon Hausmann
            shausman Simon Hausmann
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes