Koin: Bad performance in some Android devices

Created on 31 Oct 2018  路  6Comments  路  Source: InsertKoinIO/koin

Describe the bug
After some testing with a big application we've detected some performance issues.
I've written a test project to compare the performance of multiple DI frameworks. Here's an example with one of the top 3 devices owned by our users:

=========|=====================
Device:  | Huawei hwALE-H v6.0
---------|--------------------
Test:    | Koin + Kotlin
Min-Max: | 234,91-272,23 ms
Average: | 241,21 ms
---------|--------------------
Test:    | Koin + Java
Min-Max: | 374,05-382,03 ms
Average: | 376,66 ms
---------|--------------------
Test:    | Kodein + Kotlin
Min-Max: | 7,48-15,48 ms
Average: | 7,63 ms
---------|--------------------
Test:    | Kodein + Java
Min-Max: | 7,95-10,76 ms
Average: | 8,08 ms
=========|=====================

_(I excluded Dagger because it's obviously more performant)_

To Reproduce
Here's the test project with more results in the readme: https://github.com/Sloy/android-dependency-injection-performance

Expected behavior
We would expect a similar result to Kodein, below 10ms in a not-so-good device.

Koin project used and used version:
koin-android:1.0.1

core check

Most helpful comment

The biggest performance issue we found is described by https://github.com/InsertKoinIO/koin/issues/246

We ran the tests with the code from PR https://github.com/InsertKoinIO/koin/pull/258 and got better results:

Device:  | Huawei hwALE-H v6.0
---------|--------------------
Test:    | Koin + Kotlin
Max:     | 59,33 ms
Min:     | 33,93 ms
Average: | 35,35 ms
---------|--------------------
Test:    | Koin + Java
Max:     | 186,08 ms
Min:     | 165,36 ms
Average: | 170,31 ms

It's a big improvement, but can probably get better. Haven't found any other good spot for optimization yet.

All 6 comments

The biggest performance issue we found is described by https://github.com/InsertKoinIO/koin/issues/246

We ran the tests with the code from PR https://github.com/InsertKoinIO/koin/pull/258 and got better results:

Device:  | Huawei hwALE-H v6.0
---------|--------------------
Test:    | Koin + Kotlin
Max:     | 59,33 ms
Min:     | 33,93 ms
Average: | 35,35 ms
---------|--------------------
Test:    | Koin + Java
Max:     | 186,08 ms
Min:     | 165,36 ms
Average: | 170,31 ms

It's a big improvement, but can probably get better. Haven't found any other good spot for optimization yet.

You can also test with nullable logger, because by default in 1.0.1 it build visual graph and print them.
https://github.com/InsertKoinIO/koin/pull/256 but i don't think that it so significant here, but anyway.

Logging as nullable is not relevant from my last test, because we have already pre-formated the messages.

Performance improvement for 1.0.x is constrained to the actual design. I'm investigating a rewritten Koin core features, that would allow far better performances in loading & getting dependencies.

Also over complex feature like visibility checking/modules are clearlt impacting performances, whereas the value of such features (inner modules & visibility rules) is not good enough.

@arnaudgiuliani while you think on how to rewrite it you could at least merge the PR with the small performance improvement.
Anyway this issue is making Koin not usable for big apps, I hope you'll fix it soon. You can ask for contributors if you know what should be fixed or how.

After good investigating ... @kuFEAR is right. Logs are also killing it :/

Wait for the 1.1.0 release then 馃憤

Check the following 2.0.0 release for next performances announces.

Was this page helpful?
0 / 5 - 0 ratings