Implement pre-computed etag support for mbtiles sources#1918
Closed
Implement pre-computed etag support for mbtiles sources#1918
Conversation
Co-authored-by: nyurik <1641515+nyurik@users.noreply.github.com>
Co-authored-by: nyurik <1641515+nyurik@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] More performant etag support
Implement pre-computed etag support for mbtiles sources
Jul 11, 2025
for more information, see https://pre-commit.ci
Member
|
For what this PR is worth, I think this is simpler if re-done by a human. |
Member
|
I agree that this should be done by a human. The goal was to see how this system works in general, and if we can use it to solve simpler tasks |
Member
|
It definitively can - just in rust the quality of code it produces is not great. In react though.. |
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.
This PR implements more performant etag support by allowing mbtiles backends to supply pre-computed etags when available, eliminating unnecessary CPU usage from computing xxhash over tile data.
Background
CDNs rely heavily on etags (usually a hash) to identify if tiles have changed. Many
.mbtilesfiles already store tiles with pre-computed hashes using two tables - one storesz, x, y, hashcolumns, and another table storeshash, data blob. Currently, Martin computes etags by running a non-cryptographical hash function over the output even when pre-computed hashes are available, causing unnecessary CPU usage.Changes Made
1. Enhanced Source Trait
get_tile_etag()method with default implementation returningNoneSyncbound for thread safety2. Optimized MbtSource Implementation
MbtTypeduring initializationget_tile_etag()to return pre-computed hashes for supported types:MbtType::FlatWithHash: Uses hash fromtiles_with_hashtableMbtType::Normalized: Uses hash fromimagestabletile_idMbtType::Flat: ReturnsNone(falls back to computed hash)3. Updated Tile Serving Pipeline
Tilestruct with optionaletagfield4. HTTP Response Integration
get_http_response()to prefer pre-computed etag over computed hashPerformance Impact
StringtoTilestructTesting
Added comprehensive tests verifying:
Backward Compatibility
✅ Fully backward compatible - no breaking changes
Example Usage
The implementation successfully addresses the performance bottleneck described in the issue while maintaining full compatibility with existing functionality.
Fixes #1917.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.