First of all, thank you for taking a look at my question. This is the first time posting for me! Any suggestions on improving my question are welcome.
As of recently, I started writing my own games. I have created some smaller games, but, I am planning on writing a somewhat larger one. I hoped to be able to use Dependency Injection. But, I stumbled on comments suggesting a performance impact on an application's runtime when using DI.
Since runtime performance is of importance in real-time applications, I was wondering how big of an impact Dependency Injection has? And how you would go around minimizing this impact?
For now, I was planning on using the Spring Framework. Would this be a wise choice? Or should I opt for something more lightweight?
DI gets usually used to wire together the big parts at the start of the application and this is not something I'd care about. In any case, I'd go for it. Concerning some more intensive uses of DI, it's hard to tell, but I wouldn't worry much. It's all optimized and the cost is something like a lookup and a reflection.
In order to use DI, you need no framework at all. DI is the idea of "injecting" dependencies instead of using globals or alike. There are people who prefer to wire their application manually. It's not as bad as it sounds and there is no overhead. So you really should go for DI. A combined approach with manually injecting where speed matters is an easy way out of performance problems, so you won't regret using DI.
If all you want is DI, then I'd suggest using Guice. While in the meantime Spring DI can work without length XML, Guice has always been configured in Java, which I strongly prefer. It feels more like a library than a framework as it's easy to use (most of the classes need no configuration at all, many others need just a single line).
Dagger is a DI framework working at compile time: It's an annotation processor which finds out all the dependences and generates code linking your app together withou any reflection.
Google uses DI very heavily and the overhead on their scale is not negligible. They've switched some projects from Guice to Dagger and IIRC they've gained some 10% performance.