flutter_map
flutter_map copied to clipboard
Add caching in Map for loaded tiles in TileLayer to improve performance and reduce requests.
By trying to resolve flash on seamless scroll, I had an idea to try load tile images faster by caching them in Map<String,Uint8List> where key is (x:y:z) and Uint8List is image data. Then before requesting tiles from tile provider, I check if key exists and if it does, then I load it from there skipping tile request all together. It seems like it is faster to look up in Map, than in disc cache, but regarding that more tests need to be done. One thing I certainly noticed improvement on was on tile requests. While looking at network requests, it did request images from (disc cache), that was loaded previously, but a lot of them still was requested from server repeatedly, at least so appears when zooming in and out or panning. But with Map approach there are no requests if the same tiles are loaded. Well this was just an accidental experiment, see what you get out of it and maybe it has some potential.
In video you can see comparison on request. This is zooming in second time (after already loaded images once). As you can see in current version requests are made some from disk cache, some from server even once already loaded. While loading from Map, there are no requests. https://www.youtube.com/watch?v=r4ub9n4H_LA
Here you can see a comparison between both versions on zoom. As you can see storing Images in Map does load images faster. As there are less lower resolution tiles showing and less visible gray tiles. However on original version, those low resolution tiles and gray tiles could be explained by some of the tile requests on server not stored in (disc cache)? https://www.youtube.com/watch?v=Y3zLNNlTQms