perf(gpkg): connection reuse + prepared bulk-insert + keyset paging (MAPCO-11320) - #255
Open
shimoncohen wants to merge 2 commits into
Open
perf(gpkg): connection reuse + prepared bulk-insert + keyset paging (MAPCO-11320)#255shimoncohen wants to merge 2 commits into
shimoncohen wants to merge 2 commits into
Conversation
…PCO-11320) GpkgClient opened a fresh SQLiteConnection for every tile/batch operation. Hold one lazily-opened connection per client instead, guarded by a lock so the client is safe under the concurrent access Data.GetLastExistingTile (Parallel.ForEachAsync) already performs and that the service-side parallel merge will add. Open it with WAL + synchronous=NORMAL for concurrent reads and far fewer fsyncs on the hot path. - InsertTiles: bind parameters once and reuse a prepared statement per batch instead of re-adding parameters on every row. - GetBatch: keyset pagination on rowid (WHERE rowid > cursor ORDER BY rowid) instead of LIMIT/OFFSET, so page cost stays constant as the merge advances. Signature returns (tiles, lastId); Gpkg persists lastId as the batch identifier for resume. - GpkgClient is now IDisposable and closes the connection; IData : IDisposable and both apps dispose sources+target after the merge to release file locks. Migration note: the gpkg batch identifier changes from an offset to a rowid cursor. Drain in-flight gpkg-source jobs before deploying so resume checkpoints are not reinterpreted across the format change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Aug 4, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
shimoncohen
requested review from
CL-SHLOMIKONCHA,
almog8k,
asafmas-rnd,
razbroc and
syncush
August 5, 2026 08:06
shimoncohen
marked this pull request as ready for review
August 5, 2026 08:07
syncush
approved these changes
Aug 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LOGIC-1 of MAPCO-11317. Hot-path performance for
GpkgClient(shared library used by MergerService — production/OCP — and MergerCli).Changes
GpkgClientop opened a freshSQLiteConnection. Now one lazily-opened,lock-guarded connection per instance, opened withjournal_mode=WAL+synchronous=NORMAL. The lock makes it the thread-safe connection SVC-1 (MAPCO-11325) depends on, and also fixes the existing concurrent access fromData.GetLastExistingTile(Parallel.ForEachAsync).InsertTilesbinds parameters once and reuses a prepared statement per row instead of re-adding parameters each iteration.GetBatchpages onrowid > cursor ORDER BY rowid(indexed, constant page cost) instead ofLIMIT/OFFSET(which rescans discarded rows). Returns(tiles, lastId);GpkgpersistslastIdas the batch identifier.GpkgClient : IDisposablecloses the connection;IData : IDisposable; both apps dispose sources+target after the merge so file locks/WAL handles are released (matters in the long-running service).The gpkg batch identifier changes from an offset to a rowid cursor. Drain in-flight gpkg-source jobs before deploy so resume checkpoints aren't reinterpreted across the format change.
Testing
Disposeidempotency covered against real SQLite inGpkgUtilsTest; mock-basedGpkgpaging/reset/resume updated inGpkgTest.Notes
rowid(not a literalidcolumn) is used so paging works on arbitrary source gpkgs regardless of explicit PK naming.🤖 Generated with Claude Code