<div dir="ltr"><div>Hi,<br><br></div>I was looking at the perfs of qgis server and I did a small profiling of a GetMap on a road layer (linestring) with QGIS configured with defaults. We spend a lot of time converting to and from WKB. For example, for rending 67k features (3 GetMaps), we do this for each feature:<br><ul><li>When reading the features from the DB, <b>we parse the WKB</b> and convert it to a QgsLineStringV2 (array of x and array of y)</li><li>Then, in QgsSymbolV2, we get the WKB from the QgsLineStringV2 (OK, no conversion, we kept the WKB)</li><li>Then QgsClipper::clippedLineWKB uses the QgsConstWkbSimplifierPtr which uses QgsMapToPixelSimplifier::simplifyPoints:</li><ul><li><b>Parse the WKB</b> to get the bounding box</li><li><b>Parse the WKB</b> to read the points, simplify them and <b>write a new WKB</b> with the simplified geometry</li><li><b>Parse the simplified WKB</b> to read the points into a QPolygonF</li></ul></ul><p>So that is 4 parsing of WKB and 1 write WKB instead of the single parse that is really needed. I have trouble getting exact numbers but we spend roughly 15% of our time doing just that. For example, we spend globally 4.3% of our time calling 1M times QgsConstWkbPtr::verifyBound.</p><p>A few numbers (% are relative to the caller and I show only the major stuff):</p><ul><li>QgsWMSServer::executeRequest</li><ul><li>83% in getMap ->QgsVectorLayerRenderer::drawRendererV2</li><ul><li>69% in renderFeature -> QgsSymbolV2::renderFeature<br></li><ul><li>52% in QgsLineSymbolV2::renderFeature (mostly Qt rendering stuff)<br></li><li>35% in QgsSymbolV2::_getLineString -> QgsMapToPixelSimplifier::simplifyPoints</li><ul><li>46% simplifyWkbGeometry</li><li>36% calculateBoundingBox</li><li>11% QgsConstWkbPtr::operator>><br></li></ul></ul><li>25% in QgsFeatureIterator::nextFeature -> QgsPostgresFeatureIterator::fetchFeature<br></li><ul><li>79% in QgsPostgresFeatureIterator</li><li>4% QgsPostgresConn::PGgetResult</li><li>others...<br></li></ul></ul><li>17% in QgsHttpRequestHandler::setGetMapResponse</li></ul></ul><p>Now, simplifying all the WKB parse/write will gain maybe 10-15% in global perfs for this case. But there are maybe reasons for that (memory usage or I don't know)?<br></p>Why not avoiding simplifying a linestring if its bbox is in the same ballpark as the bbox we are rendering? Or maybe this logic: if bboxLS.w / nbPoints > pixelW*2 or bboxLS.h / nbPoints > pixelH*2, then we don't do simplification. The idea being points are roughly equally spaced in a linestring.<br><p>Why storing the points as two arrays in QgsLineStringV2 instead of directly a QPolygonF?</p><p>I've been focusing only on linestrings for the moment. But I guess the same applies to the other types of geometry.</p><p>I know it's a lot of questions for a single email. But I'm new to this code and have no knowledge of its history and the choices/tradeoffs that were made.<br></p><p>Thanks.</p><p><br></p><p>PS:<br></p><p>I think I've found what I'll do at Bonn's Hackfest ;-)<br></p></div>