I just finished porting my game to Entitas Redux. It went better than expected! However, my game runs considerably slower. Running the profiler tells me that the cause is ContextObserverBehavior.Update.
Unity Version:
Unity 2021.3.1f1
To Reproduce
Run any scene that uses ContextObserverBehaviour and make sure to enable profiling.
Expected behavior
ContextObserverBehavior.Update should not be a bottleneck.
I suspect that the problem is the extremely frequent call to _contextObserver.ToString(), because it coincides with a consistent 0.7 MB allocation each frame. The actual method looks reasonable enough, but it's being called way too much.
Actually, now I'm not so sure. It turns out vanilla Entitas' equivalents are implemented the exact same way, but I didn't have this problem with them.
No, wait, I think I was right the first time. Deep Profile mode says so:
Ah! It turns out I'm leaking ContextObservers. I noticed that the number of them is steadily increasing. The problem is actually with my own code. Whoops, my bad. Sorry for the confusion.
Describe the bug
I just finished porting my game to Entitas Redux. It went better than expected! However, my game runs considerably slower. Running the profiler tells me that the cause is
ContextObserverBehavior.Update
.Unity Version:
Unity 2021.3.1f1
To Reproduce
Run any scene that uses
ContextObserverBehaviour
and make sure to enable profiling.Expected behavior
ContextObserverBehavior.Update
should not be a bottleneck.Screenshots
Additional context
Looking at this code...
https://github.com/jeffcampbellmakesgames/Entitas-Redux/blob/090414b6bd3eb62d5da294bfdbc88f4f3da1e8b8/Unity/Assets/JCMG/EntitasRedux/Scripts/VisualDebugging/ContextObserver/ContextObserverBehaviour.cs#L43-L53
I suspect that the problem is the extremely frequent call to
_contextObserver.ToString()
, because it coincides with a consistent 0.7 MB allocation each frame. The actual method looks reasonable enough, but it's being called way too much.Actually, now I'm not so sure. It turns out vanilla Entitas' equivalents are implemented the exact same way, but I didn't have this problem with them.No, wait, I think I was right the first time. Deep Profile mode says so: