criticalmaps / criticalmaps-android

🤖 Critical Maps Android App
http://criticalmaps.net
Apache License 2.0
138 stars 27 forks source link

Optimize map overlays refresh #57

Closed cbalster closed 7 years ago

cbalster commented 9 years ago

I see two problems here: First of all osmdroids overlay list is backed by a CopyOnWriteArraylist which creates a new copy on every mutation. Secondly we are currently allocating new Objects for the markers on each refresh which is less then optimal (which is kinda my fault due to 9bfca7171d043e3da99f8e0d1016c012dd9ce34f ;) ). I would suggest keeping a local copy of the overlays as a normal Arraylist in MapFragment. Then we could update the existing ones and add and remove as needed on each refresh in that local list. When done we can just .clear() and .addAll() the osmdroid one. This would reduce the mutative operations to two in all cases. Thoughts?

stephanlindauer commented 9 years ago

sounds good. maybe we could also think about an object pool where we keep map markers for later use if they aren't needed anymore and should be kept from being garbage collected.

cbalster commented 9 years ago

Thought about it too. But Markers are quite cheap and I don't think the user count varies a lot (correct me if I'm wrong). Therefore I expect a full-fledged object pool to be overkill. Will take a look at this the next days.

stephanlindauer commented 9 years ago

yea no you're right they don't vary too much. worst case in berlin we have ~800 users so there might be ~10 more or less with every server call.

cbalster commented 9 years ago

okay, then I'll take care of that :)

cbalster commented 7 years ago

I actually did some testing a while back and I didn't see any advantages in performance/memory churn by changing this - not worth the effort.

stephanlindauer commented 7 years ago

:+1: