imkoi/sparse-inject: DI Container forged for game development
The fastest DI container developed by a friend of mine. I like his engineering approach and the overall high quality of the solution, which you can verify even by checking the benchmarks in the repo, as these are one of the most thorough benches for unity DI containers available online. They are conducted with a deep understanding of how a DI container is used in real games and how to measure performance correctly.
For example, benchmarks that prewarm the code in JIT-compiled environments don’t reflect real use cases, as in your game the registering stage is executed only once—unlike benchmarks where the building stage is run multiple times before measurements are taken.
Moreover, the results vary significantly between Mono and IL2CPP. I recommend checking the benchmarks and results to remind yourself how crucial it is to profile your code and not blindly trust every claim made online (yes, I’m looking at you, benchmarks in Reflex and VContainer repos).
Of course, the same applies to the benchmarks by the Sparse Inject author—if you're considering replacing your current DI container with this one, profile your code on the target platform with your existing DI container first. Then, after converting to Sparse Inject, compare the results. Ideally, test on multiple devices—the minimum supported, an average one, and a top-tier one—as performance gains may vary.
I’ve started porting my pet project from VContainer to Sparse Inject. While I love the minimal API of Sparse Inject, it also means that everything VContainer provided for Unity integration needs to be redone manually. On one hand, VContainer’s Unity integration allows you to kick-start a project quickly, but on the other, it makes switching to another DI container more difficult later as you must redo all of that.
A minimal API of sparse inject requires additional steps now to implement integration features of VContainer I used, but in the future it also makes porting to another DI much easier since you gain complete control and understanding.
Nevertheless, I’ve shared my notes with the author so he can create a migration and quick-start guides. I believe that, sooner or later, a repository with add-ons for quicker Unity integration will be created — avoiding repetitive tasks while maintaining a clean API by keeping these additions separate from the main repo.
https://github.com/imkoi/sparse-inject
#di #container #dod
Post #2474
1.1K