Farhazul Mullick
06/27/2025, 9:23 AMkoin.waitAllStartJobs()
Sergey Dmitriev
06/27/2025, 9:33 AMFarhazul Mullick
06/27/2025, 9:36 AMSergey Dmitriev
06/27/2025, 9:40 AMApplication#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 modulesFarhazul Mullick
06/27/2025, 9:43 AMkoin.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?Sergey Dmitriev
06/27/2025, 9:48 AMApplication#onCreate
you do
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
definitionsFarhazul Mullick
06/27/2025, 9:50 AMSergey Dmitriev
06/27/2025, 9:50 AMAnd what about this feature project: modules?Do you load them separately and at a later point?
Sergey Dmitriev
06/27/2025, 9:52 AMlazyModules(mainModules + featureModules)
Farhazul Mullick
06/27/2025, 10:03 AMDo 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 timeFarhazul Mullick
06/27/2025, 10:31 AMlazyModules
and loadKoinModules()
Adding lazyModule you have to add koin.waitAllStartJobs()
at your feature section, but you can instantly call loadKoinModules
at your feature?Sergey Dmitriev
06/27/2025, 10:41 AMApplication#onCreate()
you load the absolute necessary
Then for each screen you load and unload the corresponding module separately.