Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Faster JS in QML
Qt 6.11 is out! See what's new in the release blog

Faster JS in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 5 Posters 3.3k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andriy Gerasika
    wrote on last edited by
    #1

    Hello,
    does it have any sense to perform QML/JS optimizations such as:

    for (var i = 0; i < repeater.count; i++) {...}
    

    optimized:

    for (var i = 0, n = repeater.count; i < n; i++) {...}
    

    or:

                    var bucketImage = brushImage_colorAnimation.bucketImage
                    brushCanvas.color = brushImage_colorAnimation.color
                    if (bucketImage.bucketCanvas)
                        bucketImage.bucketCanvas.color = brushImage_colorAnimation.color
                    else if (bucketImage.color)
                        bucketImage.color = brushImage_colorAnimation.color
    

    optimized:

                    var bucketImage = brushImage_colorAnimation.bucketImage
                    var color = brushImage_colorAnimation.color
                    brushCanvas.color = color
                    if (bucketImage.bucketCanvas)
                        bucketImage.bucketCanvas.color = color
                    else if (bucketImage.color)
                        bucketImage.color = color
    

    i.e. basically how fast is property get in QML JS?

    Does it have any sense to excessively use local variables to cache things that definitely are not going to change?

    Thanks!

    Proud author of FunnyBalloon game for kids.

    Arvindhan PonnusamyA 1 Reply Last reply
    0
    • A Andriy Gerasika

      Hello,
      does it have any sense to perform QML/JS optimizations such as:

      for (var i = 0; i < repeater.count; i++) {...}
      

      optimized:

      for (var i = 0, n = repeater.count; i < n; i++) {...}
      

      or:

                      var bucketImage = brushImage_colorAnimation.bucketImage
                      brushCanvas.color = brushImage_colorAnimation.color
                      if (bucketImage.bucketCanvas)
                          bucketImage.bucketCanvas.color = brushImage_colorAnimation.color
                      else if (bucketImage.color)
                          bucketImage.color = brushImage_colorAnimation.color
      

      optimized:

                      var bucketImage = brushImage_colorAnimation.bucketImage
                      var color = brushImage_colorAnimation.color
                      brushCanvas.color = color
                      if (bucketImage.bucketCanvas)
                          bucketImage.bucketCanvas.color = color
                      else if (bucketImage.color)
                          bucketImage.color = color
      

      i.e. basically how fast is property get in QML JS?

      Does it have any sense to excessively use local variables to cache things that definitely are not going to change?

      Thanks!

      Arvindhan PonnusamyA Offline
      Arvindhan PonnusamyA Offline
      Arvindhan Ponnusamy
      wrote on last edited by
      #2

      @Andriy-Gerasika
      Creating local attributes cause delay in performance check the below link for more details
      http://doc.qt.io/qt-5/qtquick-performance.html

      K 1 Reply Last reply
      1
      • Arvindhan PonnusamyA Arvindhan Ponnusamy

        @Andriy-Gerasika
        Creating local attributes cause delay in performance check the below link for more details
        http://doc.qt.io/qt-5/qtquick-performance.html

        K Offline
        K Offline
        karlheinzreichel
        wrote on last edited by
        #3

        @Arvindhan-Ponnusamy
        the article you mentioned states the opposite!

        ODБOïO Arvindhan PonnusamyA 2 Replies Last reply
        0
        • K karlheinzreichel

          @Arvindhan-Ponnusamy
          the article you mentioned states the opposite!

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4

          @karlheinzreichel :D yes exactly ! it is good practice to create local copy of properties (inside js functions) work with that local 'var' and when everything is done assigne that local var value to your qml property. Otherwise That property value is reevaluated by QmlJs Engine every time you ref it thats whay it is greedy.

          You can also use Recursion for your JS functions if you want more optimization.
          But best way to optimize your application is to not use js :p or less possible.
          *Extend QML with c++

          LA

          1 Reply Last reply
          1
          • K karlheinzreichel

            @Arvindhan-Ponnusamy
            the article you mentioned states the opposite!

            Arvindhan PonnusamyA Offline
            Arvindhan PonnusamyA Offline
            Arvindhan Ponnusamy
            wrote on last edited by
            #5

            @karlheinzreichel Document States
            Things to avoid in binding expressions to maximize optimizability:
            1.declaring intermediate JavaScript variables
            2.accessing "var" properties
            3.calling JavaScript functions
            4.constructing closures or defining functions within the binding expression
            5.accessing properties outside of the immediate evaluation scope
            6.writing to other properties as side effects

            K kshegunovK 2 Replies Last reply
            0
            • Arvindhan PonnusamyA Arvindhan Ponnusamy

              @karlheinzreichel Document States
              Things to avoid in binding expressions to maximize optimizability:
              1.declaring intermediate JavaScript variables
              2.accessing "var" properties
              3.calling JavaScript functions
              4.constructing closures or defining functions within the binding expression
              5.accessing properties outside of the immediate evaluation scope
              6.writing to other properties as side effects

              K Offline
              K Offline
              karlheinzreichel
              wrote on last edited by
              #6

              @Arvindhan-Ponnusamy
              As the reference you mention states (chapter Resolving Properties):
              Just this simple change results in a significant performance improvement
              ...

              Arvindhan PonnusamyA 1 Reply Last reply
              0
              • Arvindhan PonnusamyA Arvindhan Ponnusamy

                @karlheinzreichel Document States
                Things to avoid in binding expressions to maximize optimizability:
                1.declaring intermediate JavaScript variables
                2.accessing "var" properties
                3.calling JavaScript functions
                4.constructing closures or defining functions within the binding expression
                5.accessing properties outside of the immediate evaluation scope
                6.writing to other properties as side effects

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #7

                @Arvindhan-Ponnusamy said in Faster JS in QML:

                Things to avoid in binding expressions to maximize optimizability

                The code in the OP has nothing to do with binding expressions.

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                0
                • K karlheinzreichel

                  @Arvindhan-Ponnusamy
                  As the reference you mention states (chapter Resolving Properties):
                  Just this simple change results in a significant performance improvement
                  ...

                  Arvindhan PonnusamyA Offline
                  Arvindhan PonnusamyA Offline
                  Arvindhan Ponnusamy
                  wrote on last edited by
                  #8

                  @karlheinzreichel Kindly do qmlprofiling for the qmls with and without optimization to see the difference in performance and update. Waiting to see the results.

                  1 Reply Last reply
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved