Skip to main content

Performance Benchmarks

Anchor DI is a compile-time DI framework. This page shows how it compares to Koin (a popular runtime DI framework) in real benchmarks.

All benchmarks use kotlinx-benchmark (JMH under the hood) on JVM. Higher is better (ops/ms = operations per millisecond).


Container Initialization

How fast each framework initializes its container with N bindings (mix of leaf singletons and singletons with one transitive dependency).

BindingsAnchor DI (ops/ms)Koin (ops/ms)Anchor DI Advantage
102,8775145.6x faster
100300545.5x faster
50050114.7x faster

Anchor DI's initialization is ~5x faster because its compile-time generated code directly registers pre-built Factory instances. Koin's runtime DSL (module { single { ... } }) must interpret lambda definitions and build its internal registry dynamically.

What this means for your app: For a 500-binding app, that's the difference between ~20ms (Anchor DI) and ~90ms (Koin) at startup. On mobile, every millisecond of cold start matters.


Dependency Resolution

How fast each framework resolves a dependency after initialization.

ScenarioAnchor DI (ops/ms)Koin (ops/ms)Notes
Warm singleton13,21015,442Both sub-100ns per call
Unscoped (factory)4,2083,878Anchor DI ~9% faster

For warm singleton resolution, both frameworks are extremely fast. In practice, this difference is negligible -- both resolve cached singletons in under 100ns.

For unscoped (factory) resolution, Anchor DI is slightly faster because generated Factory.create() calls constructors directly, while Koin invokes lambda closures.


The Real Win: Compile-Time Safety

Beyond raw speed, the biggest advantage of Anchor DI is compile-time validation:

Error TypeKoinAnchor DI
Missing bindingRuntime crash (NoBeanDefFoundException)Build fails
Circular dependencyRuntime crash or hangBuild fails
Scope violationRuntime crashBuild fails
Duplicate bindingSilently overwritten or runtime crashBuild fails

If it compiles, it works.


Reproducing the Benchmarks

Run the benchmarks on your own hardware:

./gradlew :benchmarks:jvmBenchmark

Results are written to benchmarks/build/reports/benchmarks/.

Configuration: 5 warmup iterations, 5 measurement iterations, 1 second each. Results will vary by machine.