10

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.

4
  • 4
    For example if you are using an aggregate function on a layer for geometry generator, this will run as many times as you need to redraw your canvas + aggregate the layer as many times as features the source layer has. So this would be quite ineffective and better solved with static layers. Same would be for a virtual layer: it recomputes every time you move your canvas. So they are really nice and useful tools, but in some applications other tools will be way more performant.
    – MrXsquared
    Commented Dec 19, 2020 at 16:36
  • Yes, that for sure is a limiting factor, however it is not primarily a limitation of expressions, but of the concept of live rendering/updating and thus in principle affects virtual layers as well. Otherwise put: expressions can also be used with the 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.
    – Babel
    Commented Dec 20, 2020 at 10:28
  • 1
    in my opinion it is a question to ask in the qgis-developer list
    – pigreco
    Commented Dec 2, 2021 at 19:03
  • For "reasonable" use (define reasonable...) I did not find performances to be a limitation. I would not use expressions for heavy duty computation of course, to me they shine when you want to keep everything encompassed and live. This saves the hassle of recreating the layer outside of QGIS, versioning, wrong file and so on. In short it allows for a more streamlined workflow for simple to moderate talks.
    – jfmoyen
    Commented Apr 6, 2023 at 15:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.