Repository navigation
[core] Prefetch low resolution tiles - #7741
Conversation
|
@tmpsantos, thanks for your PR! By analyzing this pull request, we identified @jfirebaugh, @1ec5 and @incanus to be potential reviewers. |
fc8ce2b to
da4e126
Compare
| std::vector<Feature> queryRenderedFeatures(const ScreenBox&, const optional<std::vector<std::string>>& layerIDs = {}); | ||
| AnnotationIDs queryPointAnnotations(const ScreenBox&); | ||
|
|
||
| // Tile prefatching |
|
|
||
| // Tile prefatching | ||
| void setFixedPrefetchZoom(uint32_t); | ||
| void setDynamicPrefetchZoom(uint32_t); |
|
|
||
| // Request lower zoom level tiles (if configure to do so) in an attempt | ||
| // to show something on the screen faster at the cost of a little of bandwidth. | ||
| lowResolutionZoom = parameters.fixedPrefetchZoom ? |
There was a problem hiding this comment.
This breaks if fixedPrefetchZoom is set to 0, which is a valid use case.
| lowResolutionZoom = lowResolutionZoom < zoomRange.min ? zoomRange.min : lowResolutionZoom; | ||
|
|
||
| if (lowResolutionZoom < idealZoom) { | ||
| lowResolutionTiles = util::tileCover(parameters.transformState, lowResolutionZoom); |
There was a problem hiding this comment.
In previous implementations (JS), we've called this "panZoom". Not sure if that's a better name though.
There was a problem hiding this comment.
I'm OK with that. Let's use panZoom for the sake of consistency.
| if (retain.find(tile.id) == retain.end()) { | ||
| retain.emplace(tile.id); | ||
| tile.setNecessity(necessity); | ||
| } |
There was a problem hiding this comment.
if (retain.emplace(tile.id).second) {
tile.setNecessity(necessity);
}.second is true when something was inserted, false otherwise.
| // to show something on the screen faster at the cost of a little of bandwidth. | ||
| lowResolutionZoom = parameters.fixedPrefetchZoom ? | ||
| parameters.fixedPrefetchZoom : | ||
| idealZoom - parameters.dynamicPrefetchZoom; |
There was a problem hiding this comment.
possible integer overflow here if idealZoom < parameters.dynamicPrefetchZoom?
| parameters.fixedPrefetchZoom : | ||
| idealZoom - parameters.dynamicPrefetchZoom; | ||
|
|
||
| lowResolutionZoom = lowResolutionZoom < zoomRange.min ? zoomRange.min : lowResolutionZoom; |
There was a problem hiding this comment.
Can we use std::min to make this more readable?
| Style& style; | ||
|
|
||
| const uint32_t fixedPrefetchZoom; | ||
| const uint32_t dynamicPrefetchZoom; |
There was a problem hiding this comment.
What is the use case for having both fixed and dynamic prefetch? Which one takes precedence?
There was a problem hiding this comment.
Documented now. Fixed takes precedence.
| int32_t coveringZoomLevel(double zoom, SourceType type, uint16_t size) { | ||
| zoom += std::log(util::tileSize / size) / std::log(2); | ||
| uint32_t coveringZoomLevel(double zoom, SourceType type, uint16_t size) { | ||
| zoom = std::max(0., zoom) + std::log(util::tileSize / size) / std::log(2); |
There was a problem hiding this comment.
Should this max call include the addition (which accounts for satellite tile size differences)? Otherwise, it could be impossible to use z0 for satellite tiles.
d6b1bfe to
3cc2f15
Compare
3cc2f15 to
e033cf8
Compare
|
👀 @kkaefer |
e033cf8 to
a991620
Compare
ae6d2a2 to
dfd719a
Compare
|
Should I close this as deferred? |
jfirebaugh
left a comment
There was a problem hiding this comment.
I tested this out with a dynamicPrefetchZoomDelta of 3, and it does exacerbate #7026.
Without prefetching, the flickering occurs only if you have tiles in the disk cache at a lower zoom level than the area you are panning over. With prefetching, the flickering always occurs.
So I think we should hold this feature until we fix #7026.
|
|
||
| std::unique_ptr<AsyncRequest> styleRequest; | ||
|
|
||
| int32_t fixedPrefetchZoom = -1; |
There was a problem hiding this comment.
To indicate the lack of a value, use optional rather than negative integers.
438a29d to
a49c473
Compare
|
@kkaefer is disabling partial tile rendering enough for landing this patch? I did a cheap test by simply tweaking That said, nothing stops us for landing this today, since it is still very useful for a satellite map and would spare me from rebasing this branch and it is optional anyway. |
kkaefer
left a comment
There was a problem hiding this comment.
is disabling partial tile rendering enough for landing this patch?
No. Disabling partial rendering with the patch you suggested means that older/outdated buckets can't be used either. That means that rotating a map makes it appear blank until the buckets are reparsed.
a49c473 to
db83506
Compare
|
@kkaefer rebased and ready for reviewing again. This new version enables prefetching only for raster until we fix the label flickering. On this gif you see the difference (the tiles are offline cached on both scenarios, it is even more evident when you get tiles from the network). |
db83506 to
5d960d5
Compare
| algorithm::updateRenderables(getTileFn, createTileFn, retainTileFn, | ||
| [](const UnwrappedTileID&, Tile&) {}, panTiles, zoomRange, panZoom); | ||
| } | ||
|
|
There was a problem hiding this comment.
Can we merge this call to updateRenderables into the other one by merging the panTiles into idealTiles?
There was a problem hiding this comment.
Capturing from the chat: we have a separated algorithm::updateRenderables because we don't create render tiles for pan tiles.
| optional<uint8_t> getFixedPrefetchZoom() const; | ||
|
|
||
| void setDynamicPrefetchZoomDelta(optional<uint8_t> delta); | ||
| optional<uint8_t> getDynamicPrefetchZoomDelta() const; |
There was a problem hiding this comment.
Thanks for adding the documentation, but I'm still not understanding why we need two different APIs for this. Can you please elaborate?
There was a problem hiding this comment.
The fixed is if you want to be cheap: you can set the prefetch zoom level to say, zoom level 5 and you will never have a blank spot on the map, but it will look very low res and overscaled. Soon you will get the whole world at zoom 5 in your cache.
The dynamic IMO is more interesting, but it will use more resources. You could set it to say, 2, and it will always prefetch "CurrentZoom - 2", it will pretty much make you never see blank spots with better looking overscaled tile but it will fill the cache faster and also use more bandwidth.
I find both approaches useful. We could drop the "dynamic" API and leave it to be implemented client side if you think we don't need 2 APIs.
bef817d to
87ad0f4
Compare
Sort by z order, so lower res tiles don't get rendered over high res tiles.
87ad0f4 to
05f548c
Compare
|
Would you like to implement the SDK side of this change, or should we track that in separate tickets? |
I would like to track it in a separated ticket. |

The idea is to try to cover more map area and show the user something ASAP while the other tiles are still loading.
Exposes 2 new APIs:
Fixes #1626