Lazy initialisation JodaTimeAndroid.init(context)
baole opened this issue · comments
Calling JodaTimeAndroid.init(context) takes 50-300ms to complete depending on devices. Putting this initialisation on Android's Application class will increase cold start up time (https://developer.android.com/topic/performance/vitals/launch-time#cold). As Play store considers it's a nice metric to improve user experience and (may be app store ranking). Is there any way to "lazy" initialise it and speed up app's start time?
It would be possible to delay reading the zone data until first requested. Namely, in https://github.com/dlew/joda-time-android/blob/master/library/src/main/java/net/danlew/android/joda/ResourceZoneInfoProvider.java you could delay iZoneInfoMap = loadZoneInfoMap(openResource("ZoneInfoMap"))
until absolutely necessary.
I'm a bit hesitant to make that change, though, just because it means you'd be adding execution time to some other random part of the app - changing behavior characteristics.
Within your own code, if you know you're not using DateTime
until some time way after startup, you could delay calling JodaTimeAndroid.init()
until then.
Thanks for clarification. It's better to move the init() call just before the app is actually needed Joda.