rksahu1987 / osmdroid

Automatically exported from code.google.com/p/osmdroid
0 stars 0 forks source link

Too Much Synchronize in MapTileProvider ==> Contention that slow too much the Map Display #444

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Too Much Synchronize in some class like   
 - org.osmdroid.tileprovider.MapTileProviderArray 
 - org.osmdroid.tileprovider.MapTileCache

In MapTileProviderArray  A solution is to replace 
protected final HashMap<MapTile, MapTileRequestState> mWorking;
protected final List<MapTileModuleProviderBase> mTileProviderList;
by 
protected final HashMap ConcurrentHashMap<MapTile, MapTileRequestState> 
mWorking;
protected final CopyOnWriteArrayList<MapTileModuleProviderBase> 
mTileProviderList;

That permit to remove all synchronize in the MapTileProviderArray

The change was very spectacular.... in display speed of tiles

Original issue reported on code.google.com by ttbox...@gmail.com on 28 Jun 2013 at 7:41

GoogleCodeExporter commented 8 years ago
There are very subtle locking issues in these areas and any changes to this 
area must be done with care.

Can you provide concrete numbers for the speed improvement for these changes? 
Can you also confirm that you never get "stuck" tiles that don't load with 
these changes?

Original comment by kurtzm...@gmail.com on 1 Jul 2013 at 1:22

GoogleCodeExporter commented 8 years ago
I tried the changes for MapTileProviderArray and found no difference in speed. 
I pre-cached all the tiles in zoom level 5 and then quickly panned in one 
direction. Both ways the maps loaded tiles at about the same speed. 
Additionally, I reviewed the logs and we actually used to use a 
ConcurrentHashMap for mWorking but we found that it added unnecessary locking 
overhead when we profiled the app. Since we don't have a high rate of 
concurrency, a synchronized lock worked better for us.

The CopyOnWriteArrayList would probably be a good fit for mTileProviderList. I 
don't think that would have any side-effects.

I just want to make sure also that you aren't getting confused by tiles that 
are downloaded and tiles that are cached. Naturally, cached tiles appear almost 
instantly whereas downloaded tiles take a few seconds. If you still think that 
changes to the synchronization methods dramatically change the performance of 
the maps, can you send some traces before and after the changes? 

Original comment by kurtzm...@gmail.com on 10 Jul 2013 at 8:35