Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
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

Closed

Description

@femski

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.

Activity

  1. added
    Android
    annotations
    on Oct 20, 2017
  2. tobrun commented on Oct 20, 2017

    @tobrun
    Member

    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?

  3. femski commented on Oct 20, 2017

    @femski
    Author

    @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.

  4. femski commented on Oct 20, 2017

    @femski
    Author

    Could this be the reason ?
    #9576 (comment)

  5. tobrun commented on Oct 24, 2017

    @tobrun
    Member

    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.

  6. tobrun commented on Oct 25, 2017

    @tobrun
    Member

    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.

  7. femski commented on Oct 26, 2017

    @femski
    Author

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

  8. tobrun commented on Oct 26, 2017

    @tobrun
    Member

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

  9. tobrun commented on Mar 2, 2018

    @tobrun
    Member

    This is fixed with #11111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Androidannotations

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions