MGLAccountManager.load method is slow during app startup
pilot34 opened this issue · 0 comments
I'm trying to optimize Booking app startup time. And noticed, that Mapbox is taking up to 100 ms because of the calls NSBundle.mainBundle
in MGLAccountManager
+load
method.
NSBundle.mainBundle
is slow for the first call and we can do that in a background thread after app is launched. But load
methods are called before our code is called so I cannot optimize this place.
I guess we don't really need tokens in load
method. The easiest solution will be to replace + load
method with + initialize
method that will be called only when we call MGLAccountManager
for the first time.
The proper solution will be to move NSBundle
calls to a background queue and load it asynchronously before we really need the token. And synchronize access to the token from the main thread somehow. Maybe with the same serial queue, or with read/write locks.
Steps to reproduce
- Build any app with release configuration
- Launch "Profile" in Xcode
- Launch "App Launch" instrument
Expected behavior
Main thread is not blocked during launch. We can pre-warm NSBundle.mainBundle
in background thread, and after that call MGLAccountManager
and this won't block main thread.
Actual behavior
Main thread is blocked for around 80ms during launch because we call NSBundle.mainBundle in + load
method.
Configuration
Mapbox SDK versions:
6.3.0
iOS/macOS versions:
14.3
Device/simulator models:
iPhone X
Xcode version:
12.3