Repository navigation
Serve offline map tiles ourselves, not through MapLibre's PMTiles sources - fixes memory leak - #1182
Merged
Merged
Conversation
MapLibre Native's PMTilesFileSource never removes an entry from its map of in-flight requests: not when a tile has been answered, and not when the request is cancelled, as it registers no onCancel. So every tile it reads leaves two file requests alive for good, each holding a mailbox whose queue keeps the first 4 KB block it allocated. On the test farm that showed up as the A54's native heap growing by tens of megabytes over two hours, nearly all of it held from mln::Mailbox::push. The same code is built for iOS. - The style's offline source is now a soundscape-extract:// URL, served by OfflineExtractTiles, a MapResourceProvider on the default map runtime. It builds the TileJSON from the extract's header and metadata as PMTilesFileSource did, and reads and un-gzips tiles with PmTilesReader. Up to four extracts are kept open, one read at a time each; a file that has changed is opened again, and one that has gone is dropped. - PmTilesReader also reads the header's zoom range, bounds and centre, and can return a tile already decompressed. - Tiles served this way go into MapLibre's ambient cache, keyed by a URL naming the extract's path, which is now why each download still gets a unique filename. The comments saying so are updated. Network tiles are unaffected: they don't go through PMTilesFileSource. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was previously deployed
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.
MapLibre Native's PMTilesFileSource never removes an entry from its map of in-flight requests: not when a tile has been answered, and not when the request is cancelled, as it registers no onCancel. So every tile it reads leaves two file requests alive for good, each holding a mailbox whose queue keeps the first 4 KB block it allocated. On the test farm that showed up as the A54's native heap growing by tens of megabytes over two hours, nearly all of it held from mln::Mailbox::push. The same code is built for iOS.
Network tiles are unaffected: they don't go through PMTilesFileSource.