modesttree / Zenject

Dependency Injection Framework for Unity3D
MIT License
2.54k stars 273 forks source link

MemoryPool despawn slow perfomance #86

Open ttermeer-reboundcg opened 4 years ago

ttermeer-reboundcg commented 4 years ago

Despawn function has a very slow performance. It takes 10 seconds to despawn 50k objects. This is due to the following line

Assert.That(!_inactiveItems.Contains(item),
                "Tried to return an item to pool {0} twice", GetType());

The security should either be optional or refactored to provide a faster duplicate detection.

According to Microsoft Dispose pattern (https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose), Disposable object should implement a boolean to avoid items being disposed twice. So I would argue that the security is unnecessary. However the memory pool documentation should be amended to include the proper dispose pattern.

Mathijs-Bakker commented 4 years ago

Good point/catch!