I use quite often QGIS expressions and I am wondering how performant they are compared with other possibilities. In many cases, the same problem can be resolved using different approaches like using either expressions, or a combination of GUI tools, or a query in a virtual layer, or a Python script (and others, like PostGIS).
Apart from the situation when certain goals cannot be realized by using expressions, I'm interested in the limitations regarding performance (an example below, update 2). So the question is: are there any clear criteria when expressions hit a performance limitation and turn to be less performant than Virtual layers or Python scripts?
Regarding some more complex expressions, I realized that they can quite take some time to update when used for "realtime" rendering as in these expamples here:
Re-locating points randomly at certain distance in QGIS
Create road network from points
Update 2: One limitation in the kind that I am asking for is mentioned by Ujaval Gandhi in a recent tutorial:
aggregate expressions are not yet optimized with spatial indexing
see QGIS with Ujaval Gandhi, at 1:02:21 to 1:02:53, https://youtu.be/IraiAF4s5Tg?t=3741
Update 1, to be more precise: I am primarily interested in the performance of the algorithms that run in the background when using expressions (compared to virtual layers, python etc.). Of course, using expressions for symbol layers with geometry generator is nice, but with a a lot of features and complex calculations, this dynamic approach of permanent redrawing and calculating the map canvas can be slow. But this is not primarily a limitation of expressions, but of their use for "on the fly" creation of geometries and affects virtual layers as well. Using expressions with the geometry by expression
tool does not have this limitation - however the question of performance is still relevant there.
See here for some information about Performance boost of QGIS Expressions Engine, which, however, does not directly answer the question here.
geometry by expression
tool where a new (static) layer is created - so in this case, the aspect of redrawing layers does not play any role. So maybe to be more precise, the question should be more about the performance of the algorithms that are performed in the background when using expressions. Will update the question accordingly.