<div dir="ltr">Hi PSC, devs,<div><br></div><div>Following the submission of the last part of our 2019 grant work, here's a report detailing what was undertaken and achieved thanks to these two funding grants:</div><div><br></div><div><br><b>Profile and optimise the QGIS vector rendering code</b><div><br></div><div>One of the most critical and important functions in the QGIS application is rendering of vector map layers. QGIS has an extremely powerful and flexible vector symbology engine, capable of some mind blowing cartography and visual effects. For efficient use on both the desktop and server, users require that QGIS rendering is as fast as it possibly can be!</div><div><br>During this grant project, we conducted in-depth research into code "hot spots" and inefficiencies in the QGIS rendering code using a number of code profiling tools. This work resulted in many optimisations, including:</div><div><ul><li>Cache painter path for font marker when it doesn't change (<a href="https://github.com/qgis/QGIS/pull/30860">https://github.com/qgis/QGIS/pull/30860</a>) - around 2x speed up for font marker rendering<br></li><li>Optimise checking for active properties (<a href="https://github.com/qgis/QGIS/pull/30861">https://github.com/qgis/QGIS/pull/30861</a>)<br></li><li>Fix expensive file modified time check is applied with every check of svg/image cache (<a href="https://github.com/qgis/QGIS/pull/30862">https://github.com/qgis/QGIS/pull/30862</a>) - dramatic speed up for SVG marker rendering (and SVG rendering across QGIS in general)</li><li>Optimise reading of multipoints from OGR (<a href="https://github.com/qgis/QGIS/pull/30863">https://github.com/qgis/QGIS/pull/30863</a>) - speeds up use of multipoint layers across QGIS in general (not just rendering)</li><li>Don't perform costly calculation of symbol output units which we don't use (<a href="https://github.com/qgis/QGIS/pull/30864">https://github.com/qgis/QGIS/pull/30864</a>) - speeds up all vector rendering operations</li><li>Fix unnecessary calculation of marker symbol bounds when labeling is not required for a layer and symbols layers are in place (<a href="https://github.com/qgis/QGIS/pull/30865">https://github.com/qgis/QGIS/pull/30865</a>) - speeds up rendering of simple marker points matching this situation by around 3x</li><li>Fix large speed regression in evaluating string equality expressions (<a href="https://github.com/qgis/QGIS/pull/30866">https://github.com/qgis/QGIS/pull/30866</a>) - dramatic improvement of expression calculation times across all of QGIS</li><li>Avoid expensive symbol clones during label rendering (<a href="https://github.com/qgis/QGIS/pull/30867">https://github.com/qgis/QGIS/pull/30867</a>)</li><li>Speed up copying of paint effects (<a href="https://github.com/qgis/QGIS/pull/30868">https://github.com/qgis/QGIS/pull/30868</a>)</li><li>Add a reserve method to QgsGeometryCollection (<a href="https://github.com/qgis/QGIS/pull/30892">https://github.com/qgis/QGIS/pull/30892</a>) - speeds up use of multi geometry types across all of QGIS</li><li>Avoid storing and cloning paint effects for layers if they are just the default stack unchanged (<a href="https://github.com/qgis/QGIS/pull/30896">https://github.com/qgis/QGIS/pull/30896</a>)</li><li>Optimizations for shapeburst rendering (<a href="https://github.com/qgis/QGIS/pull/30982">https://github.com/qgis/QGIS/pull/30982</a>)</li><li>Much faster copying of expression contexts with a project scope present (<a href="https://github.com/qgis/QGIS/pull/30983">https://github.com/qgis/QGIS/pull/30983</a>)</li><li>Avoid lots of unnecessary work involving disabled label data defined properties (<a href="https://github.com/qgis/QGIS/pull/30986">https://github.com/qgis/QGIS/pull/30986</a>)</li><li>Optimisations to QgsProperty which greatly speed up data defined symbology rendering in some circumstances (<a href="https://github.com/qgis/QGIS/pull/31159">https://github.com/qgis/QGIS/pull/31159</a>)</li><li>Big speedup when loading symbols with embedded paths <a href="https://github.com/qgis/QGIS/pull/31333">https://github.com/qgis/QGIS/pull/31333</a>)</li><li>Add a fast shortcut to rectangle/geometry intersection test (<a href="https://github.com/qgis/QGIS/pull/31340">https://github.com/qgis/QGIS/pull/31340</a>)</li><li>Speed up geometry equality checks by orders of magnitude (<a href="https://github.com/qgis/QGIS/pull/31341">https://github.com/qgis/QGIS/pull/31341</a>)</li><li>Speed up geometry operations involved in tracing and snapping (<a href="https://github.com/qgis/QGIS/pull/31415">https://github.com/qgis/QGIS/pull/31415</a>)</li><li>Avoid using expensive geos polygon overlap calculation for two horizontal labels (<a href="https://github.com/qgis/QGIS/pull/31937">https://github.com/qgis/QGIS/pull/31937</a>) - speeds up label rendering on complex maps</li><li>Limit number of label candidates for large layers (<a href="https://github.com/qgis/QGIS/pull/31975">https://github.com/qgis/QGIS/pull/31975</a>) - on complex projects can reduce label rendering time by an order of magnitude</li></ul><div>While the focus of this work was on the vector rendering code, some of the optimisations implemented have resulted in dramatic improvements across other parts of QGIS also (such as certain Processing algorithms).</div></div><div><br></div><div>These optimisations were made available in the QGIS 3.10.0 release, with selected low-risk optimisations also being backported to the QGIS 3.4 LTR series.</div><div><br></div><div><b>"Rebalance" the labeling engine and fix poor automatic label placement choices</b><br></div><div><b><br></b></div><div>While QGIS has a powerful engine sitting behind its automatic label placement, the labeling results generated by this engine were often unpredictable and frustrating for users. Labels were frequently positioned over other features, and regardless of how heavily users tweaked the various label settings it could be impossible to avoid these unwanted labels. Furthermore, the settings for controlling individual layer label and feature obstacle priorities generally had no discernible effect on the actual placement of labels on the map.<br></div><div><br></div><div>During this work project we commenced by safe guarding the existing label placement logic with a series of new carefully designed unit tests covering a range of different label placement situations. We then used these reference tests as a guide and re-worked the label placement engine logic. Now, labels will never be placed over features from a layer with a a higher obstacle weight when compared to the label's priority.</div><div><br></div><div>This logic dramatically simplifies the effect of labeling settings for users, avoiding the complexities and bugs which were present in the older approach.</div><div><br></div><div>In order to avoid disrupting existing projects, the new labeling logic is only used for newly created projects in QGIS 3.12 and later. We added a mechanism to allow users to manually upgrade existing projects to the newer logic, via the project's label settings dialog.</div><div><br></div><div>Lastly, we used this opportunity to invest some much-needed time in modernising and cleaning up the labeling engine code, to help make it easier to understand and maintain in future.</div><div><br></div><div>(<a href="https://github.com/qgis/QGIS/pull/33183">https://github.com/qgis/QGIS/pull/33183</a>)</div><div><br></div><div><br></div><div><br></div><div>Nyall</div><div><br></div><div><br></div><div><br></div><div><br></div></div></div>