Optimize PMTiles memory usage and integrate shared caching#18
Merged
groldan merged 3 commits intotileverse-io:mainfrom Dec 29, 2025
Merged
Conversation
Introduces a centralized caching infrastructure to optimize memory usage across multiple RangeReader instances. - Shared Cache Architecture: Added Cache, CacheManager, and SubCache abstractions in io.tileverse.cache. Multiple logical caches now share a single underlying Caffeine cache instance, allowing for global eviction policies and shared weight limits across the application. - RangeReader Integration: Refactored CachingRangeReader to use RangeReaderCache, which acts as a view (sub-cache) of the shared global "tileverse-rangereader-cache", keyed by the source identifier. - HTTP Optimizations: Updated HttpRangeReader to use a shared CachedThreadPool for HttpClient. - API Updates: CachingRangeReader.Builder now accepts a CacheManager. This architecture prevents memory fragmentation and ensures that total cache usage respects global limits rather than per-instance limits.
c0ef581 to
02cd166
Compare
Refactors the PMTiles implementation to reduce memory footprint
and leverage the new shared caching infrastructure.
- Zero-Allocation Optimizations:
- Optimized HilbertCurve to use primitive math and binary search
for zoom level lookup, eliminating object allocation during tile ID conversion.
- Replaced ByteBufferInputStream with CompressionUtil utilities that
stream directly from SeekableByteChannel through BoundedInputStream and Channels,
avoiding intermediate buffer copies.
- Refactored PMTilesEntry to an interface with value-based implementations
(Leaf, Tile) to minimize object overhead for directory entries.
- Updated PMTilesDirectoryImpl to use binary search on the packed ByteBuffer
for entry lookups instead of deserializing all entries into objects.
- Shared Caching Integration:
- Integrated PMTilesReader and PMTilesVectorTileStore with CacheManager
to use shared cache resources.
- Implemented DirectoryCache and VectorTileCache as views of the shared cache,
ensuring efficient eviction and global memory limits.
- API Improvements:
- Updated PMTilesReader API to use TileIndex consistently and expose
getTileId for direct access.
- Removed redundant internal buffering logic in favor of the shared
ByteBufferPool and direct channel operations.
This changeset significantly reduces heap pressure when reading large
PMTiles archives and improves concurrent read performance.
02cd166 to
9e45c38
Compare
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.
Refactor the PMTiles implementation to reduce memory footprint and leverage the new shared caching infrastructure.
This changeset significantly reduces heap pressure when reading large PMTiles archives and improves concurrent read performance.
Refactor caching to use shared Caffeine cache with SubCache support
Introduces a centralized caching infrastructure to optimize memory usage across multiple RangeReader instances.
This architecture prevents memory fragmentation and ensures that total cache usage respects global limits rather than per-instance limits.