Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

addImage is slow (takes 3-4 ms for each icon) #10249

Closed
femski opened this issue Oct 20, 2017 · 8 comments
Closed

addImage is slow (takes 3-4 ms for each icon) #10249

femski opened this issue Oct 20, 2017 · 8 comments
Labels
Android Mapbox Maps SDK for Android annotations Annotations on iOS and macOS or markers on Android

Comments

@femski
Copy link

femski commented Oct 20, 2017

Platform: Android
Mapbox SDK version: 5.2 Beta 1

Steps to trigger behavior

  1. Generate 2000 Icons on a background thread
  2. 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.

@fabian-guerra fabian-guerra added Android Mapbox Maps SDK for Android annotations Annotations on iOS and macOS or markers on Android labels Oct 20, 2017
@tobrun
Copy link
Member

tobrun commented 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
Copy link
Author

femski commented 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
Copy link
Author

femski commented Oct 20, 2017

Could this be the reason ?
#9576 (comment)

@tobrun
Copy link
Member

tobrun commented Oct 24, 2017

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:

ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount());
bitmap.copyPixelsToBuffer(buffer);

I'm going to benchmark some alternatives to the setup above.

@tobrun
Copy link
Member

tobrun commented 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
Copy link
Author

femski commented Oct 26, 2017

Yes, if calls are moved to non-blocking thread it will be much better.

@tobrun
Copy link
Member

tobrun commented Oct 26, 2017

fwiw the long term fix for this that would result in the best performance in #9333

@tobrun
Copy link
Member

tobrun commented Mar 2, 2018

This is fixed with #11111

@tobrun tobrun closed this as completed Mar 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android annotations Annotations on iOS and macOS or markers on Android
Projects
None yet
Development

No branches or pull requests

3 participants