The new Qt Quick Compiler - get QML to run at a speed close to native
January 14, 2022 by Vladimir Minenko | Comments
As most of you know, QML is an interpreted language. The flexibility of any interpreted language always comes with a potential decrease in performance. As we are very convinced of many other potentials of QML, we strive to reduce - if not to completely eliminate - this unpleasant potential. We implemented changes in the last Qt5 releases and especially in Qt6 helping to take a significant step towards our long term goal: make QML run at a speed close to native. This blog post explains what is new. The upcoming two blog posts will elaborate the technology and its development history.
Today, we are proud to announce that we will introduce the new Qt Quick Compiler™ with Qt 6.3. The new Qt Quick Compiler will consist of two components: the QML Type Compiler and QML Script Compiler. The QML Type Compiler will compile QML object structures into C++ classes. The QML Script Compiler will compile functions and expressions in QML files of an application into C++ code. As much as possible, since there will be some limits set by the nature of JavaScript. If certain statements cannot be compiled, regular interpretation and caching will be used. Some changes in the code of the application might be needed to achieve the best possible results over time. New QML tools will help you detect these. For example, the new QML Lint, for example, will tell you which parts of the code cause fallbacks into interpretation. We will expand and improve QML tools in the future in our aim of making them a guide to Best Practices for all components in Qt Quick. The closer you follow the recommendations reported by these tools, the more QML code can be compiled and, thus, run faster. Speaking of "faster": one of the future blog posts will also show the first benchmark results.
As an initial step we are providing a Technology Preview of the QML Script Compiler for commercial customers. It is available as of today in the "Qt for Device Creation" package released with Qt 6.2.1. This Technology Preview will continue in 6.2.x releases of "Qt for Device Creation". Starting with Qt 6.3, the base components of the Qt Quick Compiler will also be integrated in the QtDeclarative module. This is an important step for us to ensure the creation of better and faster QML code by all users in the Qt community. While the QML Script Compiler might pass its Technology Preview already in 6.3, the Technology Preview for the QML Type Compiler will only start with 6.3. Depending on the results of these preview phases, we will later decide about a first general release.
Starting with Qt 6.3, we will additionally make Qt Quick Compiler Extensions available for Qt commercial users. Qt Quick Compiler Extensions will decrease the refactoring effort to improve coverage of compilation. Qt Quick Compiler Extensions are also planned to offer additional tooling or integrations for existing tools meant to provide a better understanding of how specific parts of the code influence execution performance of the application in the project and which changes in the code are needed to make these parts compile. More extensions are in development. In total, we expect that up to 30% speed-up can be achieved in the startup and execution over time.
Any compiler needs code to work with. This is the only way to evolve and get better and better, faster and faster. Please reach out to us! Ideally, via Qt Bug Reports and with samples of code which you expected to compile. The relevant component on the "QTBUG" project is "QML: Compiler".
Blog Topics:
Comments
Subscribe to our newsletter
Subscribe Newsletter
Try Qt 6.9 Now!
Download the latest release here: www.qt.io/download.
Qt 6.9 is now available, with new features and improvements for application developers and device creators.
We're Hiring
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.
Commenting for this post has ended.
this sounds great and motivates to do all the refactorings to port my projects from 5.15 to 6.3 :)
Is there a possibility to be released for open-source users?
Not just a "possibility", it is the case! I probably was not clear enough on this in the text. Only Extensions will be commercial-only.
So it is allowed to used in LGPL3 projects? Even phoronix did get the wording mixed up, and people in the forums are crying about FOSS projects missing out:
https://www.phoronix.com/scan.php?page=news_item&px=Qt-6.3-Alpha
Please edit the blog post to be less confusing. Also, how do I enable it in cmake?
Sure! I now inserted "additionally" into the first sentence about Extensions. Moreover, I believe the part of the text saying "the base components of the Qt Quick Compiler will also be integrated in the QtDeclarative module. This is an important step for us to ensure the creation of better and faster QML code by all users in the Qt community" makes it clear as well, since the QtDeclarative module is generally available under the dual license, and the text says that we are making this new functionality available for "all users in the Qt community". I hope it helps.
Speaking of CMake, the new Qt Quick Compiler will be enabled by default if you use the new QML Modules, see https://www.qt.io/blog/qml-modules-in-qt-6.2. There will be an option to disable it and use the QML Cache generation if desired. More detailed information about this and other options will be provided in the docs latest at the time of the final release.
This is fantastic! For GUI the declarative approach makes a lot of sense. Having some of the accompanying performance drawbacks taken away is really huge. Curious whether QSGRENDERLOOP latency due to the vsync implementation/animation driver is also on your radar. That is the last remaining issue remaining for me with QML, many don't even consider it a problem unfortunately
Can you elaborate on the latency issue; does this refer to an existing issue in Jira perhaps? There are some on-going minor improvements for vsync handling in Qt Quick for Qt 6.4 and beyond, but those are probably not directly related to what you are referring to here.