Unsolved Faster JS in QML
-
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!
-
@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 -
@Arvindhan-Ponnusamy
the article you mentioned states the opposite! -
@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
-
@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 -
@Arvindhan-Ponnusamy
As the reference you mention states (chapter Resolving Properties):
Just this simple change results in a significant performance improvement
... -
@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.
-
@karlheinzreichel Kindly do qmlprofiling for the qmls with and without optimization to see the difference in performance and update. Waiting to see the results.