Zenject icon indicating copy to clipboard operation
Zenject copied to clipboard

Large scenes and pools get ridiculous loading times because of the Resources.FindObjectsOfTypeAll<ZenjectBinding>() in "Context" class

Open Extrys opened this issue 4 years ago • 0 comments

Problem

Our scenes take to load like 2:30 min due to every time a new gameObject component has to be injected and for this the "Resources" static call for each object has to be called in order to look for all ZenjectBindings in the Scene

  • this call happens A LOT of times

I have tried to remove that call tweaking the context to enable scene injection and without that call, my scenes take just 4s.

my tweak for that doesn't work for instantiated items through factories, because the install phase happens before being able to reference the ZenjectBinding to the Contexts

image

Reproduction

This happens just using Zenject in large scale projects with lots of items makes this noticeable

Expected Behaviour

ZenjectBinding Should add itself to its contexts, before installing phase avoiding the FindObjectsOfTypeall<ZenjectBinding>() making the game load faster and instantiate things also faster

  • Zenject version: 9.2
  • Unity version: 2021.1
  • Project's scripting backend IL2CPP

A workaround for installing items to scenes, is using Array.ForEach(Container.ParentInstallers, x=>x.Bind(ObjectToBind));

Extrys avatar Apr 08 '21 10:04 Extrys