playMaker

Author Topic: How can you find where GC.collect is coming from on Playmaker  (Read 1945 times)

autumnboy

  • Junior Playmaker
  • **
  • Posts: 73
How can you find where GC.collect is coming from on Playmaker
« on: September 03, 2019, 08:48:31 AM »
Hi all,
I seem to be getting GC.Collect spike (407 ms) from a playmakerLateupdate.lateupdate() that's on my enemies. I'm using the profiler but How can I dig deeper via playmaker to find out what's causing this?
It seems to be happening randomly or delayed.
I also don't understand the nature, would a action be calling this, forcing gc or causing the engine to push a gc collect?

It's visible in editor and build.

Any help would be great thanks,

Josh

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: How can you find where GC.collect is coming from on Playmaker
« Reply #1 on: September 03, 2019, 09:29:09 AM »
Hi.
Do you use some create/destroy actions?

These are the biggest garbage makers.

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: How can you find where GC.collect is coming from on Playmaker
« Reply #2 on: September 03, 2019, 02:08:35 PM »
Hi all,
I seem to be getting GC.Collect spike (407 ms) from a playmakerLateupdate.lateupdate() that's on my enemies. I'm using the profiler but How can I dig deeper via playmaker to find out what's causing this?

Deeper? Like Deep Profile deeper? That's an option in the profiler, but I'm not sure it will tell exactly what eats CPU time in detail, only the method that does it when called.
Garbage collection management is a bit tricky, it can sometimes produce some spikes. Do you use the small heap action? It's to dump some garbage every n frames.

autumnboy

  • Junior Playmaker
  • **
  • Posts: 73
Re: How can you find where GC.collect is coming from on Playmaker
« Reply #3 on: September 03, 2019, 08:36:17 PM »
Hi all, thanks for your responses.

I found the problem by slowly isolating where gc spike was coming from. It was also very delayed so pinpointing it took time.

 I'm at the end of my project so finding where it was coming from was a little difficult.

I'm pooling majority of game objects and rarely create/destroy.

For anyone who might have the same problem due to the action.

Found the playmaker.lateupdate > gc.collect spikes was coming from a custom action:
Calculate Agent distance by corners

A replacement for this action is:
Get Agent Remaining Distance

Cheers,
Josh
« Last Edit: September 03, 2019, 08:38:58 PM by autumnboy »

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: How can you find where GC.collect is coming from on Playmaker
« Reply #4 on: September 04, 2019, 05:43:46 AM »
Good to know. Was it using some obsolete code? (was there a yellow warning about it?)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: How can you find where GC.collect is coming from on Playmaker
« Reply #5 on: September 04, 2019, 08:15:18 AM »
Hi.

Just mentioning, obsolete code(yellow warnings) do mot mean that it will create garbage.

yellow warnings only mentions that on a later version, certain code will not be used anymore.
The reason certain code will be obsolete can be for various reasons.

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: How can you find where GC.collect is coming from on Playmaker
« Reply #6 on: September 04, 2019, 09:46:54 AM »
I wrote the action. I cannot remember offhand, but I doubt any of it is obsolete. The action is necessary at times because calculating the distance the standard way will throw errors if there are too many corners. (For example in a maze with many turns). When calculating the distance remaining, you dont need to do it in update. Just a few times a second is enough, which would save on lots of garbage collection. Also, small amounts of garbage are really not an issue for any modern hardware.  8)

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: How can you find where GC.collect is coming from on Playmaker
« Reply #7 on: September 04, 2019, 09:53:41 AM »
Hi.

Just mentioning, obsolete code(yellow warnings) do mot mean that it will create garbage.

yellow warnings only mentions that on a later version, certain code will not be used anymore.
The reason certain code will be obsolete can be for various reasons.

Exactly. Also, it may highlight a script (such as an action) that points to another script which might have been altered in parts in the meantime. This, with the update of engines and plugins, might sometimes cause issues although they won't throw any error. It's rare but not impossible.

autumnboy

  • Junior Playmaker
  • **
  • Posts: 73
Re: How can you find where GC.collect is coming from on Playmaker
« Reply #8 on: September 04, 2019, 10:02:57 PM »
I wrote the action. I cannot remember offhand, but I doubt any of it is obsolete. The action is necessary at times because calculating the distance the standard way will throw errors if there are too many corners. (For example in a maze with many turns). When calculating the distance remaining, you dont need to do it in update. Just a few times a second is enough, which would save on lots of garbage collection. Also, small amounts of garbage are really not an issue for any modern hardware.  8)

I needed to grab distance every frame. In my case I've had a bit of trouble with it reliably grabbing the distance anyway. It wasn't a small amount of garbage collection, over time it resulted in huge cg.collect spikes (407 ms) from multiple instances, troublesome enough to effect any modern hardware.

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: How can you find where GC.collect is coming from on Playmaker
« Reply #9 on: September 04, 2019, 11:33:47 PM »
Hi, did some profiling and testing. For the OP, its too bad the action didnt work they way you were hoping.

As for other people who come across this thread, for future reference. One agent using it on update has 88kb of garbage, which is not bad at all. Doing 58 agents (2 were resting of my 60), had 5KB of garbage, which is a little bit higher. But is causing me 0.57ms of CPU (of course different devices should be different). Great for PC, less great for mobile, but it was 60 agents on screen. Again, doing the check 10 x per second, etc would make little to no noticeable HUMAN difference to stopping distances. That would cut down on the garbage a lot.

I ran my test for quite a while. The garbage collector will take out the garbage on a regular basis, so there should be no build-up unless there is a problem somewhere else.

The garbage collection is due to 2 internal methods that unity uses to do its calculations, so there is no way to avoid it in this action. Again, I suggest using this action when it is necessary (check to see if the standard "Get Remaining Distance" is ever returning infinity. If there are more than 2 corners in a path, this is a known issue. See my screenshot for the garbage collection location.

As for its accuracy, it remains just as accurate as other methods. Again, did a little test.

The action is throwing no yellow warnings. Therefore, this action works as expected.

Again to OP, glad you got it worked out for your setup!