https://kotlinlang.org logo
Title
a

arnaud.giuliani

12/16/2019, 2:02 PM
is it
synchronized
/ monitor expression?
k

Kirill Rozov

12/16/2019, 2:19 PM
Yes
Koin inject implemented as
inline fun <reified T : Any> ComponentCallbacks.inject(
        qualifier: Qualifier? = null,
        noinline parameters: ParametersDefinition? = null
) = lazy { get<T>(qualifier, parameters) }
That is the same
lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
    get<T>(qualifier, parameters)
}
That implementation has impact on performance
We need options to use unsafe lazy (
lazy(LazyThreadSafetyMode.NONE)
) for injecting
a

arnaud.giuliani

12/16/2019, 2:39 PM
on Android you mean?
k

Kirill Rozov

12/16/2019, 2:42 PM
On any platform
It’s not good always use synchronization
a

arnaud.giuliani

12/16/2019, 2:50 PM
yes, I see
on one side, we don’t know if current environment is running multithread or not
but the other, we lock instance resolution in the tree ... then we should not be exposed to problem
and then we would allow LazyThreadSafetyMode.NONE
k

Kirill Rozov

12/16/2019, 2:56 PM
I think it will be good to have option for inject without thread safety
Resolution of an instance must be locked inside depencies tree, not via lazy resolution from client side (via lazy delegate)
a

arnaud.giuliani

12/16/2019, 3:15 PM
sure
I’m reworking internal engine to clearly optimize just to lock in on tree resolution
k

Kirill Rozov

12/16/2019, 3:30 PM
👍
I can create issue for that on Github
Do you need it?
a

arnaud.giuliani

12/16/2019, 3:33 PM
yes open a ticket
I can make some work around it directly 😉
k
I’m reworking internal engine to clearly optimize just to lock in on tree resolution
You need to lock only
scoped
and
single
dependncies, because factory need to be created every time and no need to lock thread for resolution
a

arnaud.giuliani

12/16/2019, 3:49 PM
this is what this is in current engine version
check
SingleInstanceFactory
&
FactoryInstanceFactory
k

Kirill Rozov

12/16/2019, 6:21 PM
I’ll check it later today
Done
a

arnaud.giuliani

12/17/2019, 8:17 AM
thanks