SupportMapFragment loads extremely slowly the first time, but quickly in subsequent loads (including different Activities)
Asked Answered
B

0

8

My app has three different Activities that use a SupportMapFragment. There is a major delay on the first load after starting the app. This slow load time does not occur on subsequent loads, even if I go back and access a completely different Activity (that also contains a map). I'm trying to figure out if this is something that I could fix.

This gist shows how I load the SupportMapFragment. Using debug points I have determined that the slowness occurs between onViewCreated and onStart.

Update 1: Using Debug I have taken two traces of the first load and second load. The second load is in a completely different Activity. I quickly noticed that the first trace (the slow load) has a LOT of calls to java/util/zip/zipEntry. I don't see any calls like that in the second trace. Also, this delay happens between onCreateView and onViewCreated of the MapFragment.

Update 2: This also happens with a MapFragment (not support), except the delay is actually much longer.

Update 3: This SO question seems to be related. Also this one.

Burnt answered 17/11, 2014 at 16:19 Comment(9)
Why are you using nested fragments, rather than extending SupportMapFragment or just using it directly?Scalenus
@Scalenus I am using it in a ViewPager, so I load a Fragment that loads and configures the SupportMapFragment.Burnt
"I am using it in a ViewPager" -- so? That does not justify the overhead and general icky-ness of nested fragments. Here is a sample project showing using maps in a ViewPager, without nested fragments. Note that I happen to be using MapFragment rather than SupportMapFragment, but that should not impact the solution. If you want to use nested fragments in places, go right ahead, but do so only in the absence of less-expensive solutions.Scalenus
@Scalenus I have refactored such that the ViewPager is in the Activity and the CustomMapFragment is a direct Fragment. There is still almost a two second delay when first loading. Could this be an issue with the SupportMapFragment? I could convert since we dropped API 10 support after our last version release.Burnt
"Could this be an issue with the SupportMapFragment?" -- tough to say, but I doubt it. Use Traceview to determine where your time is being spent, rather than just log statements. My guess is much of this time is part of initializing the communications with the Play Services Framework and it starting to download map tiles, and that's not something that you can readily change.Scalenus
Using Debug I have taken two traces of the first load and second load. The second load is in a completely different Activity. I quickly noticed that the first trace (the slow load) has a LOT of calls to java/util/zip/zipEntry. I don't see any in the second trace. Also, this delay happens between onCreateView and onViewCreated.Burnt
@Scalenus It is seeming like there is no way around the delay, which I hate because it effects neighboring fragments in the ViewPager too (OffscreenPageLimit has to be at least 1).Burnt
See my answer over there https://mcmap.net/q/461811/-how-to-improve-fragment-loading-speed. It is still working.Jegar
Possible duplicate of what makes my map fragment loading slow?Smacking

© 2022 - 2024 — McMap. All rights reserved.