Dependency Injection Patterns: Efficiency and Usability
summary
Compares concrete outcomes: static polymorphism (templates + concepts) produces direct calls and inlining so it avoids runtime indirection on hot paths; indirect calls from virtual methods or std::function often add size and runtime cost unless link-time optimization or specific compiler heuristics remove them. Tests use gmock and mockable vector/mutex to prove behavior; examples include wrapping C APIs, a synchronized deque adapter, and experiments on x86_64/ARM with GCC Clang and MSVC at O3/-Os showing compiler-dependent differences.
AI-written summary · about
chapters (21)
- 0:00Dependency injection in C++
- 1:05Why DI matters
- 3:56Domain requirements for DI
- 8:11Performance trade-offs
- 9:37Runtime polymorphism explained
- 13:39Code generation for virtual calls
- 20:33Advantages and limitations of runtime polymorphism
- 21:59Type erasure wrappers
- 26:15Performance overhead of polymorphic function wrappers
- 30:20Function pointers for DI
- 36:25Optimizing function pointers
- 37:49Runtime polymorphism optimizations
- 40:18Static polymorphism alternative
- 42:47Code generation for static poly
- 46:02Class templates for DI
- 49:43C++20 concepts for contracts
- 51:34Compile-time techniques combined
- 57:00Injecting functions without overhead
- 1:00:37Static polymorphism benefits
- 1:03:24Performance recommendations
- 1:04:28Q&A
related talks
01h 00mHow to Use Dependency Injection to Write Maintainable Software
03mLightning Talk: Dependency Injection for Modern C++
57mDesign Patterns - The Most Common Misconceptions (2 of N)
06mLightning Talk: Cute Approach for Polymorphism in C++
01h 03mRetiring the Singleton Pattern
49mApplied Modern C++: beyond type erasure and visitor pattern
56mLaw of Demeter: A Practical Guide to Loose Coupling
01h 02mBreaking Dependencies - The Visitor Design Pattern in Cpp
