Performance Highlights v0.2.1

~9ns
Singleton Resolution
~1ns from manual DI!
~24ns
Transient Creation
Factory + Arc allocation
~56ns
Scope Pool Acquire
Reusable scopes for web
~4ns
Frozen Contains
Perfect hash lookup

Optimization Journey

Phase 1-4
Lock-Free Foundation
AtomicBool, enum factories, batch API, derive macros
Registration: 854ns → 250ns
Phase 5-6
Caching & Pooling
Thread-local cache + scope pooling
Resolution: 19ns → 14ns
Phase 7-8
Fluent API + Fast Downcast
Chainable batch + unchecked Arc downcast
Batch: 333ns → 243ns
Phase 9-10
Deep Chains + Perfect Hash
Full hierarchy + MPHF for frozen containers
Contains: 10ns → 4ns
Phase 11
Fast Bit-Mixing Hash
Golden ratio multiplication + single lookup
Resolution: 14ns → 9ns
Final
~1ns from Manual DI
Full DI features with near-zero overhead
8ns manual → 9ns DI
@if (benchmarkService.loading()) {
Loading benchmark data...
} @if (benchmarkService.error()) {
{{ benchmarkService.error() }}
} @if (!benchmarkService.loading()) {
{{ benchmarkService.processedBenchmarks().length }}
Benchmarks
{{ getLastCommit() || 'N/A' }}
Latest Commit
{{ getLastUpdate() || 'N/A' }}
Last Updated
@for (benchmark of benchmarkService.processedBenchmarks(); track benchmark.name) { }
Benchmark Current Previous Change Trend
{{ benchmark.name }} @if (benchmark.range) { {{ benchmark.range }} } {{ formatValue(benchmark.current, benchmark.unit) }} {{ benchmark.previous !== null ? formatValue(benchmark.previous, benchmark.unit) : '—' }} {{ getChangeIcon(benchmark.changePercent) }} {{ formatChange(benchmark.changePercent) }} @if (benchmark.history.length >= 2) { } @else { }
Faster (improvement)
Slower (regression)
No significant change

Comparison with Other Approaches

We benchmarked dependency-injector against common DI patterns in Rust. All tests use the same service types and measure equivalent operations.

Approach Singleton Resolution Container Creation 4-Thread Concurrent Notes
Manual DI ~8 ns ~88 ns N/A Baseline, no runtime lookup
HashMap + RwLock ~21 ns ~7.6 ns ~93 µs Reader contention under load
DashMap (basic) ~21 ns ~670 ns ~89 µs Lock-free, good scaling
dependency-injector ~9 ns ~80 ns ~90 µs ~1ns from manual DI!

Service Count Scaling

Resolution time remains constant regardless of registered services:

10 services: 9.0 ns
50 services: 9.0 ns
100 services: 9.0 ns
500 services: 9.1 ns

O(1) lookup thanks to ahash + DashMap + fast bit-mixing

Concurrent Scaling (100 reads/thread)

Near-linear scaling as threads increase:

1 thread: ~40 µs (400 ns/op)
2 threads: ~60 µs (300 ns/op)
4 threads: ~90 µs (225 ns/op)
8 threads: ~180 µs (225 ns/op)

Lock-free reads + thread-local cache = high throughput

~1ns from Manual DI

At ~9ns per resolution, dependency-injector is within 1ns of manual dependency injection while providing full runtime DI features.

Lock-Free Concurrency

DashMap + thread-local cache eliminates lock contention. ~90µs for 4 threads × 100 reads each.

Rich Features

Scope pooling, deep parent chains, derive macros, perfect hashing, JSON logging — all with near-zero overhead.

Benchmark Methodology

Environment

  • Ubuntu Latest (GitHub Actions runner)
  • Rust 1.85+ stable toolchain
  • All features enabled (--all-features)
  • Release mode with LTO optimizations

Configuration

  • Criterion.rs 0.5 benchmarking framework
  • 100 samples per benchmark
  • 3-second warmup period
  • Statistical analysis with 95% confidence

What We Measure

  • Registration: Container + service setup
  • Resolution: Hot cache + cold path lookup
  • Scoped: Pool acquire + parent chain
  • Concurrent: Multi-thread scaling

Key Dependencies

  • DashMap 6: Lock-free concurrent hashmap
  • ahash: Fast TypeId hashing
  • once_cell: Lazy initialization
  • boomphf: Perfect hashing (optional)
}