Excessive GC from EntityCommandBuffer.Playback

A significant portion of the GC in our main loop is coming from line 1139 of EntityCommandBuffer. 6kb/frame!!!

Assert.IsTrue((m_Data->m_RecordedChainCount == initialChainCount), "RecordedChainCount (" + m_Data->m_RecordedChainCount + ") != initialChainCount (" + initialChainCount + ")");

Most of the other asserts are commented out. I’m guessing this should have been or wrapped in a build switch?

Are you testing this at runtime? Asserts should be stripped in a build.

-edit- actually they might exist in a dev build haven’t tested, but they should definitely be stripped in a full release build.

IsTrue (as all othre methods in Assert) under [Conditional(“UNITY_ASSERTIONS”)] and should be stripped from build

They are stripped in a release build, but profiling is usually done on dev builds or in editor so we have more insight and get builds faster than an IL2CPP release compile. Nobody wants to wait 30 mins for a compile every time they change one or two lines to optimize the core loop and start looking for the next worst offender.

I think that the garbage is created by this part of your assertion:
“RecordedChainCount (” + m_Data->m_RecordedChainCount + “) != initialChainCount (” + initialChainCount + “)”

Strings are the absolute champions in the contest of the garbage generation. And here your every assertion causes the creation of a new string (4 strings to be exact), which goes as an argument to Assert.IsTrue.

So the partial solution is to put an immutable string here (“m_RecordedChainCount is not equal to initialChainCount”).
If it signals you an error, you can put a break point and find the source of the problem.

They don’t in build. The Conditional attribute on a method means that calls to the method are omitted from the compiled code.

It’s not his assertion is entities package assertion.

2 Likes