Closed unadlib closed 1 week ago
Hey @unadlib,
Inversify's architecture has their pros and cons. It allows to provide a vast variety of features other libraries simply can't. But as you correctly guessed it comes with a cost: the planner relies on complex graphs which are constantly being recreatead. Therefore, inversify needs to create the plan and traverse it to instantiate the object. Generating plans comes with an intensive use of GC, allocating and freeing a vast amount of objects, that's not performant friendly at all.
But singleton instances are cached, you should enjoy the benefits of caching this way.
So, are you saying container.getAll
is not relying on cached singleton instances? Just to know, let's try to figure out a way to recreate this with a relatively simple case.
Closing the issue since no additional details nor a minimum reproduction code were provided. I'm open to reopen the issue once we get more info to diagnose the issue and work on it.
Expected Behavior
When using InversifyJS with the singleton pattern and explicit dependency injection:
container.getAll()
to retrieve dependency instances should not cause significant performance degradation, even with complex dependency graphs.Current Behavior
container.getAll()
to iterate through the list and obtain each dependency instance becomes increasingly slow with larger and more complex dependency lists.Possible Solution
container.getAll()
.container.getAll()
that is more efficient for large dependency graphs.Steps to Reproduce (for bugs)
container.getAll()
to retrieve instances of these dependencies.Additional context: