You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
addImage is slow (takes 3-4 ms for each icon) #10249
add Icons to map using addImage("icon_name", Bitmap) on main thread
Expected behavior
addImage for 2000 icons should take no more than 500 ms.
Actual behavior
Takes 3400 ms on my fairly potent Moto Z Force (Snapdragon 620) phone.
First 100 or so icons take 1 ms or less - last few hundred are taking 3-4 ms each. Changing the size of icons does not change timings. So this is not due to any re-scaling etc.
Since we have now deprecated MarerView on android this is the only way to get a large number of icons on Map. SO it woud be important to get this fixed. Perhaps a bulk add API can be added or internal data structures improved.
Thank you for writing up this analysis, will look into doing some bechmarking myself and see where we can improve performance. That said, have you tried adding these images as sprites to your style and reference those sprites as your icon image in a symbolLayer?
@tobrun these are airport icons (with exact runway orientation) - there are thousands of them - but I can pre-render them for sure. I was not sure if they would fit in a spite. isn't sprite limited by size ? I was pleasantly surprised that I could add so many images with addImage and use then a symbol icons. Just little slower than expected. For now I have limited to 600 or so largest airports. But I will investigate sprite idea too. Thank you for your prompt response.
Been doing some tests related to exposing mapboxMap#addImages using 37 images:
with iterating over a collection and adding with addImage: 11.535209 ms
use collection with addImages: 10.229011 ms
Taking in account your data for 2000, this would result in 70ms improvement. This shows we aren't getting much improvement and the main reason is that a large part of the time is spend on the following code that is found in both implementations of addImage/addImages:
One idea I'm looking into is doing the heavy lifting of converting the Bitmap to a byte array in a background job and see if we get a better results, in any case it will limit blocking the main thread.
Activity
tobrun commentedon Oct 20, 2017
Thank you for writing up this analysis, will look into doing some bechmarking myself and see where we can improve performance. That said, have you tried adding these images as sprites to your style and reference those sprites as your icon image in a symbolLayer?
femski commentedon Oct 20, 2017
@tobrun these are airport icons (with exact runway orientation) - there are thousands of them - but I can pre-render them for sure. I was not sure if they would fit in a spite. isn't sprite limited by size ? I was pleasantly surprised that I could add so many images with addImage and use then a symbol icons. Just little slower than expected. For now I have limited to 600 or so largest airports. But I will investigate sprite idea too. Thank you for your prompt response.
femski commentedon Oct 20, 2017
Could this be the reason ?
#9576 (comment)
tobrun commentedon Oct 24, 2017
Been doing some tests related to exposing
mapboxMap#addImagesusing 37 images:Taking in account your data for 2000, this would result in 70ms improvement. This shows we aren't getting much improvement and the main reason is that a large part of the time is spend on the following code that is found in both implementations of addImage/addImages:
I'm going to benchmark some alternatives to the setup above.
tobrun commentedon Oct 25, 2017
One idea I'm looking into is doing the heavy lifting of converting the Bitmap to a byte array in a background job and see if we get a better results, in any case it will limit blocking the main thread.
femski commentedon Oct 26, 2017
Yes, if calls are moved to non-blocking thread it will be much better.
tobrun commentedon Oct 26, 2017
fwiw the long term fix for this that would result in the best performance in #9333
tobrun commentedon Mar 2, 2018
This is fixed with #11111