Repository navigation
perf(data): GeoPackage export uses 16 KiB pages where they pack rows far better - #3038
Conversation
…far better A row of about 2 KiB takes a whole 4 KiB page of a new GeoPackage and leaves half of it empty. The export now packs its first 1,000 rows into pages of both sizes and makes the file with 16 KiB pages when they need under nine tenths of the space. A feature's box is also computed once, not for its blob, the index and the table separately.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Code reviewBugs: None found. I checked the following:
Security: None found. The page size is an integer from a fixed set and goes into a Performance:
Quality (not posted inline; for the release quality pass):
AGENTS.md: No breaks found.
Twins checked:
Previously raised concerns: None. Change sizeCompared with
|
…h rows A chunk a definition query emptied said nothing about the rows to come, but the table was made from it: 4 KiB pages for the whole file, and no multipoints seen. The table now waits for the first run with rows; an empty layer's is still made at the end of the feed.
📖 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 |
| geometry.saturating_add(values.sum()) | ||
| }) | ||
| .collect(); | ||
| let wide = table_bytes(&rows, WIDE_PAGE).saturating_add(OTHER_PAGES * (WIDE_PAGE - PAGE)); |
There was a problem hiding this comment.
The page-size comparison is not the one the doc comment describes. The wide side adds the other tables' growth (OTHER_PAGES * (WIDE_PAGE - PAGE)), but the narrow side carries no baseline for those same pages. The doc asks for the whole file's space to be compared, which is wide_table + OTHER_PAGES * WIDE_PAGE against narrow_table + OTHER_PAGES * PAGE. The current form makes 16 KiB win about 6 KiB of table space too easily near the 90% line (roughly OTHER_PAGES * PAGE / 10 of the threshold). The test rows sit well away from that line, so the tests don't catch it.
If the current threshold was tuned on purpose, the doc should say which baseline it uses. Otherwise the fix is:
| let wide = table_bytes(&rows, WIDE_PAGE).saturating_add(OTHER_PAGES * (WIDE_PAGE - PAGE)); | |
| let wide = table_bytes(&rows, WIDE_PAGE).saturating_add(OTHER_PAGES * WIDE_PAGE); | |
| let narrow = table_bytes(&rows, PAGE).saturating_add(OTHER_PAGES * PAGE); | |
| (wide.saturating_mul(10) < narrow.saturating_mul(9)).then_some(WIDE_PAGE) |
I have not run the tests with this change. The calibration numbers in the PR description came from the current formula, so re-measure before changing it.
Category: quality
There was a problem hiding this comment.
This form is deliberate, and it is what the doc says: the feature table's rows at 16 KiB, "counting what the other tables' pages grow by", against the rows at 4 KiB, within nine tenths. It compares what the choice changes rather than the whole file, so the threshold doesn't loosen with the fixed baseline, and the calibration in the PR body was measured with it. If the doc should spell that out more plainly, that is left for the release quality pass.
Code reviewThe PR makes GeoPackage exports use 16 KiB pages when rows pack much better, and computes each feature's box once. I found no crash paths, no silent losses, and no unwrap/expect/unsafe in the non-test code. The fix for the earlier empty-run thread is in Bugs
Security
Performance
Quality
AGENTS.md
Twins checked
Already raised
Change sizeCompared with
|
Summary
Exporting 100,000 buffered points (polygons of about 2.1 KB a row) writes a 417 MB GeoPackage, nearly half of whose feature table is empty: only one such row fits in SQLite's default 4 KiB page. Writing and syncing that space is a good part of the export.
A new file is now made with 16 KiB pages when its rows pack much better in them.
mainwrites.Trade-off: in a 16 KiB file, a later edit rewrites 16 KiB for each page it changes instead of 4. Page size is part of the SQLite file format, and the browser's GeoPackage reader takes any size.
Safety: journal and sync settings are unchanged. A new file is still built beside the destination, synced, and moved into place without replacing anything.
Memory: the estimate holds 1,000 integers (8 KB) and copies no layer data. Peak memory is unchanged.
Not done: a larger page cache gained nothing when measured. Encoding rows on several threads would save little (geometry encoding is around 0.1 s of CPU here; the rest of the insert is SQLite on its one connection). Loading the R-tree, about 0.5 s on one thread, is the biggest part of the writer's own work left, and would be a separate change.
Surfaces: this is the one GeoPackage writer, so the desktop app,
rustgis-cli, Python, the Assistant, MCP, plugins and the phone get it. The browser doesn't write GeoPackage. No command or parameter changes. Nothing new to undo: an export doesn't change the project.Testing
Timings. Release
rustgis-cliat e48daeb, before and after:layer.addData,gp.runbuffer 5 km,share.exportLayerto a new.gpkg, the wholerustgis-cli run. Medians of 7 rounds after a warm-up, before and after alternating, through the host queue on a shared 8-thread machine.Where the export's time went (UTM, an instrumented build with each page size, medians of 5):
The rest of the 2.8 s run in that build is loading, buffering, and converting to longitude/latitude (the last two on several threads).
Reading the file back (5 rounds): adding it as a loaded layer takes 0.74 → 0.46 s. Adding it streamed and drawing a view takes 2.03 → 1.93 s, and the two PNGs are identical.
Same contents. With
SOURCE_DATE_EPOCHset,sqlite3 .dumpof the files written before and after is identical for both inputs, rows and R-tree nodes included; only the page layout differs.PRAGMA integrity_checkandrtreecheckpass, an independent GeoPackage validator reports nothing, and spatial-filter counts match.Test.
geopackage_pages_follow_the_row_sizechecks the page size and the read-back for small, 2 KiB, large, mixed, text-only and empty layers, written whole and streamed, and that adding a table leaves an existing file's pages alone. It fails with the choice switched off (4096 where 16384 is expected).The full CI run on the fork passed on this head.
UI evidence
No visible UI change.
Related issue
Part of #1227.
Summary by CodeRabbit