-
-
Notifications
You must be signed in to change notification settings - Fork 860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor tile removal #1596
Refactor tile removal #1596
Conversation
Previously pruning logic was spread around in a way that made it hard to reason about. TileImage contained variables only relevant to pruning which would be partially updated whilst loading tiles and partially updated whilst actually pruning. Considering that loading can happen without pruning this led to unnecessary computation and just made it hard to follow the pruning logic. Pruning and evicting logic is now contained in TileRemovalState which will make testing and making changes far easier.
…th pruning disabled
…eImages with no errorImage from being marked as ready to display. Also fixed handling of errors when tile fading is disabled.
028ed3b
to
05a6f5f
Compare
@ibrierley I figure it makes more sense to continue discussing your comment on improving pruning here. I don't completely understand the difference in what you have proposed, but I'm definitely keen to explore any options for improving this logic. |
@rorystephenson I think Ian's on holiday for now. I will say that maybe it would be a good idea to mix a partial resolution for #1430 into this. Essentially, just a way for the image provider and/or tile provider to detect that the tile has been pruned: this will allow for future usage to cancel the ongoing HTTP request. |
@JaffaKetchup if I understand right that issue is about having a mechanism for cancelling in-progress tile requests? I think that's definitely a worthwhile feature. It sounds like some people who want it should actually use the tile transformer to prevent loading lots of tiles during movement but that doesn't cover all use cases. I wonder if it belongs in a separate PR to make the change history clearer. |
The issue with that is it would delay loading the tiles that are actually wanted.
Possibly. The actual HTTP cancel mechanism is not yet implemented in Dart (dart:http), but it may be soon. I was just suggesting implementing the rough framework (as they both cover pruning): I made a rough implementation with a shared |
Yeah, this was more intended for slow networks. There's a limit on the number of IO HTTP threads, so on a slow network, a standard user pinch zoom gesture would need to wait for all the tiles to fully load before loading the final (useful) ones. I wasn't aware of the different pruning options for failed tiles, but it is indeed intended to handle outdated cached tiles. Perhaps no customizability is needed, I can't think of why it would be. Error tiles should work the same/similar way as other tiles, but they should be more aggressively reloaded.
Agreed, I have noticed this before. Maybe we group this in with another PR with the cancel loads feature. |
…ing the panBuffer and keepBuffer rather than choosing the higher of the two
Nice that's a good use-case to be aware of.
This was initially added in #576 although I'm not even sure if it's necessary anymore. It was specifically added to resolve a bug where tiles that previously loaded with an error would have their (non-existent?) image cached and when re-loaded would not show any image. I have tested with the default eviction and tile provider (no eviction, NetworkTileProvider) as follows and the bug was not reproduced (the new tiles loaded):
So I wonder if, when using a different TileProvider, this is still relevant or not?
Yeah I think that sounds like a good idea. |
Sure, if you manually reload the tiles, they will reload. However, as your screen recording above shows, they will not reload automatically. Perhaps we should try to re-request them on any interaction, even if we would not usually refresh/prune/add/remove them. Or maybe we need a timer of some sort. |
I definitely agree with this although, despite what the name implies, this is not what the EvictErrorTileStrategy option was initially intended to do. It was introduced to fix a bug where previously errored tiles couldn't be loaded anymore because there was a (presumably blank) entry in the ImageProvider's image cache for the error tile. The fix was to call Here's what the different
Note that with the last two options they affect more than just image cache eviction for error tiles. They can actually cause removal (pruning) of error tiles when they wouldn't usually be pruned and thus those error tiles will be reloaded on the next movement/tile event. These options will not prune tiles in the visible or keep bounds and reloading of those tiles won't happen until the next tile load is triggered by further movement. These options seem far too limited to me and EvictErrorTileStrategy seems to be a leaky abstraction in the sense that it's controlling more than just error tile image eviction (eviction != pruning). We need to figure out if evicting entries from the image cache is necessary for error tiles. This depends on whether tile providers behave differently (is it possible for a error tile image to be cached with some providers?) and whether an entry is added to the image cache for error tiles at all. Depending on those two factors we should either always or never evict error tile image cache entries. Apart from that we should aim to provide better behaviour when tiles fail to load, some scenarios (let me know if you can think of others):
The desired behaviour also depends on the TileProvider used. It's unlikely that a user will want to retry a tile load for tiles that are provided by AssetTileProvider. Since the original error image eviction behaviour was added a lot has changed and I think, now that tiles are represented by Given the complexity of all of this it may make more sense to first finish this PR which will simplify further pruning/evicting changes before attempting to tackle error tile reloads in a separate PR. |
Ok, lets leave all of that for another PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM apart from this comment.
Tile pruning/removal is complicated and hard to follow because the relevant code is spread around various classes and not executed in a linear fashion. When loading tiles their 'current' value is updated and then later when pruning it is used to determine whether a tile should be kept or not. This PR attempts to simplify error tile removal and pruning by making it a linear operation and avoiding changing the state of TileImages during this operation.
One big benefit of this change is testing tile pruning/evicting becomes much easier. This is important because there are tricky scenarios that we need to support like keeping tiles visible whilst zooming out until a tile at a lower level is fully loaded. In fact when making these changes I realised that right now we have a bug in this. Try using the web demo, disabling internet and zooming out. The tiles from the previous higher zoom disappear.