Understanding Dagger 2's Codegen implementation
summary
Dagger 2 generates zero-arg factories and then composes them into a dependency graph, does compile-time cycle checks, and strips unused bindings so dead features disappear. Optimization strategies include ahead-of-time inlining (an experiment with thousands of bindings inlines 100% of factories so no generated factories remain), ProGuard eliminating Dagger entirely (removes Dagger after ProGuard), preferring static module methods for ~15–20% faster invokes, and using @Binds instead of @Provides to avoid wrapper objects and extra method calls.
AI-written summary · about
chapters (9)
- 0:00Understanding Dagger 2
- 1:18public interface Provider
- 2:02final class Bar @Inject Bar(Foo foo) {}
- 2:51final class Baz static Baz create(Bar bar)
- 5:29OK, neat trick
- 7:23What's the catch?
- 7:59Dagger optimizations
- 9:46DI-friendly choices
- 11:37Optimizable APIS
related talks
35mDagger Reflect - The circle from runtime to compile time and back to runtime
54mCode Generation from A to Z
41mA (K)night with Dagger - Slicing problems of newbies
56mThe Wonders of Java Annotation Processing at Compile Time
36mAnnotation Processing 101
55mMaking Java More Dynamic
56mDI Frameworks – some hidden pearls
27mKotlin Backstage
