Thursday, June 11, 2020

Javascript is faster than C++

Can Javascript in QML beat C++ in Speed?

Few have challenged that Javascript can be faster than C++. If one takes the challenge literally, C++ is always faster than Javascript. However, with the overhead of Qt libraries and the QML interpreter, performance can skew dramatically.

Can Javascript be faster than C++? Yes. The following are scenarios where code should be in Javascript instead of C++.

Friday, June 5, 2020

Speed Benchmark: Number crunching in QML versus C++

Performance of Javascript versus C++

The objective is to compute the difference in number crunching performance between:
  • Javascript in QML, versus
  • raw C++

Outcome of Benchmark

Unsurprisingly, Javascript is significantly slower than C++. While it takes Javascript about 2.95 seconds to count from 1 to 1 million, which it takes C++ much lesser than 0.01 second to do the same.

There is no difference in performance between Javascript in .qml file, Javascript in old style Javascript file and Javascript in ECMAScript (ES7) .mjs file.

Wednesday, June 3, 2020

Speed Benchmark: Calling QML function versus Javascript function versus QObject

QML Function Call Performance Comparison

Is calling QML functions faster than calling Javascript functions? How about calling QObject functions? Which has speed advantage?

Note that this is merely calling functions but not running for-loops and while-loops. The intent is to compare this speed of calling Javascript functions to the speed of calling QObjects functions.

Outcome of Benchmark

Surprisingly, calling Javascript .mjs functions (referred to by Qt as ECMAScript modules, which conforms to Javascript ES7 standards) is 40% faster than calling either QML functions or old style Javascript functions.

Calling C++ QObjects from QML is 344% slower than calling another function in a native QML object!

Monday, June 1, 2020

QML Binding Loop (Part 2)

Example 2: Binding Loop Not Related To Sizing a QML object

Most binding loop examples uses sizing and positioning to describe the QML binding loop predicament. The following is an example where a binding loop is evinced without relation to sizing and positioning of QML objects.

Saturday, May 30, 2020

Future topics


Topics on the horizon

  • Themes & palette
  • Qt slots vs a pure C++ function vs Javascript function (speed comparison)
  • Qt message queue not preemptive at times
  • Using Promise or Qt.callLater() to make an application more snappy
  • Difference between a Rectangle and Item
  • Difference in speed between a QAbstractModelItem vs QML ListModel/ListElement
  • Difference in speed/memory between Rectangle and Pane
  • QML language bug: unable to resolve "this" when in an arrow function
  • How to use Javascript modules along with QML files
  • The drawback of declarative programming (using Loader to lazy load & load async)
  • Easily pass C++ objects to QML without using QObjects
  • Using Qt.callLater() to solve binding loops
  • What to do when ListView or TreeView redraws are too slow
  • How are binding loops broken?
  • What is the difference between "property var x" and "property string x"?
  • Difference between a Qt/QML object versus a Javascript object
  • Difference between a Javascript string and a QML string




Saturday, May 23, 2020

The Dreaded QML Binding Loop (Part 1)

What is a Binding Loop

The dreaded
Binding loop detected for property <xxx>
is a familiar error message for many QML developers. It is also a dreaded message because finding out where the binding loop is takes time. One cannot find it with a debugger. Once found, fixing it will be another time consuming task because it requires re-architecting or re-designing your code.

A binding loop is where one property depends on the value of another property (usually embedded in another QML type), and the other property somehow, through a long chain of dependencies, depends on the value of the original property.

What Is Declarative Programming in QML

The QML Declarative Programming Scene

It is not uncommon to see many developers, who believe they practise declarative programming in QML, to have been thought the wrong way of declarative programming by their colleagues or incumbent QML experts. With this chain reaction, the wrong way to program declaratively gets propagated from software engineer to software engineer. Before long, the QML code base becomes highly complex and difficult to manage. Sometimes, developers refer to it as a mine field.