The QML Disk Cache#
QML documents are generally pre-compiled or cached after compilation.
When using qmake you can specify
CONFIG += qtquickcompiler to the qmake command line. By default, it is enabled for release and profile builds. qmake cannot pass as much information to the Qt Quick Compiler as CMake. Therefore, the compilation will contain less native code.
You should make sure to load your QML documents from the resource file system where possible. Otherwise the QML engine won’t be able to find the code compiled ahead of time.
If no byte code or native code can be found for a QML document at run time, or if the code is found but cannot be used, the QML engine compiles the document into a byte code representation on the fly. The compiling process can be time consuming, and the result will contain only byte code. Subsequent loads of the same document will yield the same byte code. The QML engine can optimize this step by caching the result of the compilation. It stores the byte code in a cache file and later loads the cache file instead of re-compiling when the same QML document is requested again. Usually, the cache files are stored in a subdirectory
qmlcache of the system’s cache directory, as denoted by QStandardPaths::CacheLocation.
Checks are in place to make sure that any cache files and any code compiled ahead of time are only loaded if all of the following conditions are met:
The Qt version has not changed
The source code in the original file has not changed
The QML debugger is not running
QML_FORCE_DISK_CACHE variable (see below) overrides only the condition regarding the QML debugger. The other environment variables do not influence these conditions.
The primary way of fine tuning the behavior regarding ahead of time compiled code and caching is via the environment variable
QML_DISK_CACHE. This variable takes a comma-separated list of options, for example:
The available options are as follows:
Load the compilation units compiled ahead of time and allow execution of any native code found in them.
Load the compilation units compiled ahead of time and allow interpretation and just-in-time compilation of byte code found in them.
Furthermore, you can use the following environment variables:
Specifies a custom location where the cache files shall be stored instead of using the default location.