Hey, can anyone tell me, where to call this fn for...
# koin
f
Hey, can anyone tell me, where to call this fn for best performance in MyApplication class or featureModules entrypoint?
Copy code
koin.waitAllStartJobs()
s
Perhaps somewhere where you can put it behind a loading screen, splash screen or similar?
👍 1
f
So will int inc app startup time?. Because koin in its documentations says it should be called when lazyModules() are passed in koin application?
s
It will decrease your
Application#onCreate
(assuming you are loading modules there) time by loading modules in the background So that way you can show your first UI earlier, however you’d need to make sure that that UI doesn’t use any of those lazy loading modules and wait for those modules are loaded
koin.waitAllStartJobs()
before going further where you can start use those modules
f
so,
koin.waitAllStartJobs()
should be called at each feature project: module? am i correct. If so then simply loadKoinModule(module) method should do the job by calling it in an io thread? Isn't it?
s
No sure I’m following, but it all depends on how you configure Koin I assume in
Application#onCreate
you do
Copy code
startKoin {
    // load lazy Modules in background
    lazyModules(lazyModules)
}
Then the loading begins and you exit from
onCreate
You first
Activity
starts and this is where you need to wait for the modules to complete loading When
waitAllStartJobs
completes you can proceed and start injecting from
lazyModules
definitions
👌 1
f
And what about this feature project: modules?
s
And what about this feature project: modules?
Do you load them separately and at a later point?
Otherwise you just pass it together with the rest
Copy code
lazyModules(mainModules + featureModules)
f
Do you load them separately and at a later point?
No, right now loading all the modules in onCreate() by calling
loadKoinModules()
So, app startup time got increased in prod. Approach1: i can call
loadKoinModules()
in individual feature section of app like cart, home, settings, etc. Would be an effort. Approach2: using lazyModules -> But here as well
koin.waitAllStartJobs()
would have to call before injecting dependencies from koin in feature module. So this method has to be called in each feature section. or just calling it in
Application#onCreate()
will do the job and reduce start-up time
Technically i am not getting the differnce between
lazyModules
and
loadKoinModules()
Adding lazyModule you have to add
koin.waitAllStartJobs()
at your feature section, but you can instantly call
loadKoinModules
at your feature?
s
To be honest I think Approach1 is the way forward. In
Application#onCreate()
you load the absolute necessary Then for each screen you load and unload the corresponding module separately.
👌 1