Repository navigation
Conversation
Encoding is the longest single-threaded part of drawing a raster to a file. The encoder's default, level 6, takes more than twice as long as level 4 on an elevation model's shades, for a file about 4% smaller. The pixels are the same.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 13 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Code reviewI found no bugs, security issues, or AGENTS.md breaks in this change. I left no inline comments. What I checked
Limits of this review
Low-confidence notes (not posted)
Prior reviews: none exist on this PR, so no earlier concerns were left alone. Change sizeCompared with base: the whole PR against
|
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the |
|
Closing: this only speeds up map export, not drawing in the app, and the exported files grow by up to 4.8%. Not worth the trade. |
Summary
When the benchmark draws a DEM to a file, PNG encoding is the longest single-threaded step.
render_pngused tiny-skia's encoder, which deflates at level 6. It now encodes through theimagecrate, already a dependency ofrustgis-render, at level 4, with each row's filter still chosen by the encoder. The pixels are the same; files are a little larger. It also no longer clones the finished picture before encoding it.The trade-off
Encoding alone, one thread, median of 7 to 9 encodes on a shared, loaded machine:
Times from different rows were taken at different loads, so compare within a row. Other settings tried: a fixed "up" filter was quicker on some pictures but made the photograph 8% larger; level 1 and the fast mode made the DEM picture more than twice as large. Encoding on several threads could go further, but needs a PNG writer of our own, so it isn't part of this.
Timing
Whole
rustgis-cli run(add the DEM, zoom to it, export 1600×900), release builds, 25 runs each with the builds taking turns, through the job queue on a shared 8-thread machine (load average about 9). Median wall and CPU time. This PR was measured together with #3011, so the middle column is its baseline:main(336a178)main)main)Roughly where the remaining time goes, from a profile: band statistics 50 ms, reading and decoding 40 ms, encoding 35 ms, setting up the coordinate system 30 ms, drawing 20 ms, and the rest in allocating the bands, starting the process and other work.
The COG still draws no faster than the plain GeoTIFF. A raster of this size is held whole, so both decode every cell and the overviews aren't read. Drawing from them would mean reading the file in place (as large tiled GeoTIFFs are since #2772), which also takes statistics and colours from an overview and draws no cast shadows. This PR doesn't change which rasters are read that way.
Output
Decoded pixels are identical between
mainand the two changes together for map exports of the DEM and its COG, six other GeoTIFF layouts of it, the buildings and the sample map.Surfaces
Every map image
render_pngmakes:share.exportMapon the desktop, in the browser, on the command line, from the Assistant and MCP, Python'srender_png, and animation frames. The raster pictures in a self-contained web map page come from the same function and count against the page's picture limit, so a page within a few percent of that limit could now be refused. A map PDF's one-picture fallback decodes the PNG again, so its size doesn't depend on this. Layout exports and other PNG writers are unchanged. Nothing saved in a project changes.Testing
an_exported_png_holds_the_drawn_pixels: a picture with see-through pixels decodes to the same values from the new encoder as from tiny-skia's.cargo fmt --all --checkpassed.UI evidence
No visible UI change: the exported pixels are identical.
Related issue
Part of #1227.