diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2020-02-12 16:16:46 +0200 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2020-02-12 20:49:26 +0200 |
commit | 80cb05420a86ed53815cae7fb2cb3fddf07dd1d1 (patch) | |
tree | 89273d393aa76b507b345f8c18ae626c224a89c9 /src | |
parent | efb7dd0b7b942d3bcccae599f42dcc76bfd824ae (diff) | |
download | qtlocation-mapboxgl-80cb05420a86ed53815cae7fb2cb3fddf07dd1d1.tar.gz |
[core] Fix excessive onSpriteLoaded() notifications
What happened:
The excessive `onSpriteLoaded()` notifications were caused by the trick inside `OnlineFileRequest::completed()` implemenation,
which causes receving of two file source updates pointing to the *same* data in case the network response is `notModified` and
the local storage has the sprite sheet already stored inside.
In the SpriteLoader` implementation, it resulted in 2 extra `parseSprite()` calls and 2 extra `onSpriteLoaded()` notifications.
Then, the excessive `onSpriteLoaded()` notifications affected style images and all the unnecessarily added image dupes (btw,
the amount of these dupes `= 2 * number of style images`) were treated by the `RenderOrchestrator` as *updated* images.
Further, `RenderOrchestrator` called `ImageManager::updateImage()` for the updated images and the `ImageManager` populated the
`updatedImageVersions` map.
Finally, at every frame all the geometry tiles iterated through the `updatedImageVersions` to check whether their uploaded
textures needed patching.
All the mentioned above had a negative performance impact.
The fix:
Now, `SpriteLoader` sends `onSpriteLoaded()` notifications only if the data in the file source response is different comparing
to the existing one.
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/sprite/sprite_loader.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/mbgl/sprite/sprite_loader.cpp b/src/mbgl/sprite/sprite_loader.cpp index 56f7abd50b..6051de7ef4 100644 --- a/src/mbgl/sprite/sprite_loader.cpp +++ b/src/mbgl/sprite/sprite_loader.cpp @@ -58,9 +58,9 @@ void SpriteLoader::load(const std::string& url, FileSource& fileSource) { } else if (res.noContent) { loader->json = std::make_shared<std::string>(); emitSpriteLoadedIfComplete(); - } else { + } else if (loader->json != res.data) { // They can be equal, see OnlineFileRequest::completed(). // Only trigger a sprite loaded event we got new data. - loader->json = res.data; + loader->json = std::move(res.data); emitSpriteLoadedIfComplete(); } }); @@ -73,8 +73,8 @@ void SpriteLoader::load(const std::string& url, FileSource& fileSource) { } else if (res.noContent) { loader->image = std::make_shared<std::string>(); emitSpriteLoadedIfComplete(); - } else { - loader->image = res.data; + } else if (loader->image != res.data) { // They can be equal - see OnlineFileRequest::completed(). + loader->image = std::move(res.data); emitSpriteLoadedIfComplete(); } }); |