playMaker

Author Topic: [SOLVED] Consistent GarbageCollection Spike...Yikes  (Read 11578 times)

SteveB

  • Playmaker Newbie
  • *
  • Posts: 29
[SOLVED] Consistent GarbageCollection Spike...Yikes
« on: September 04, 2013, 10:37:13 AM »
The GC spike happens every 20 seconds +/-, with the other 19 seconds enjoying an avg. time of 0.1 ms - 0.25ms, with Animator.Update and PlayMakerFSM.Update() taking up the brunt of the CPU at a mere 1ms (see attachments).

Even if just for my own sanity so I understand what is happening. No panic button yet as my performance on the iPhone 5 and Mini are rock solid 30FPS, but a guide or tips on things to look out for/avoid when using PlayMaker to make it as efficient as possible (note: ...the most expensive thing I have going on right now are two Raycasts, one set to an interval of 2, and the other limited to a layer with very few colliders, with everything else being most Get/Set Property and some Position setting).

Thoughts?

Thanks so much!

-Steve
« Last Edit: September 05, 2013, 08:36:10 PM by Alex Chouls »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Consistent GarbageCollection Spike...Yikes
« Reply #1 on: September 04, 2013, 09:25:10 PM »
Animator.Update() is all Unity. There are quite a few things in Unity that create small amounts of garbage like this...

I ran some quick tests and didn't see any spikes in PlayMakerFSM.Update(). But maybe one of the actions you're using is creating garbage. I'd need to look at your project to debug it.

Also there is some overhead in the Editor. You should double check the results by attaching the profiler to a standalone build.

If you're still seeing spikes, please send me the project and I'll take a look...

SteveB

  • Playmaker Newbie
  • *
  • Posts: 29
Re: Consistent GarbageCollection Spike...Yikes
« Reply #2 on: September 04, 2013, 09:43:29 PM »
I only mentioned the Animator.Update() as one of the two things with the highest utilization; ignore that I mentioned it. :)

Sending the project would be problematic, so can we brainstorm a bit?

I run a pretty efficient development here, avoiding unnecessary checks and high order math, and I'm only using PlayMaker partially, perhaps arguably split evenly between PM and old fashion coding. My FSM's are fairly rudimentary averaging 1 to 2 states, with two being a bit more robust at 5 - 7 states. I have three raycasts, two with higher intervals and one checking against limited colliders. I have one state that is doing several float operators(add) and one multiply. A great many are Get/Set's for position and rotation, several for Get/Set properties from my 'regular' scripts and I have five iTween's (move Update, Rotate To, punch Position/Rotation) and a couple Look At's. Of this loose list I'm not suggesting they are all executing at the same time, haha, just that that is what I'm dealing with. At any give time very few are executing unless I need them to loop, otherwise only when I ask for them to execute.

I understand the above is perhaps a ridiculous paragraph and not terribly helpful, but maybe you can see I'm trying to use PM as efficiently as possible, as I'm already concerned that PM may be a tad heavier than doing all of it with pure code.

Can you give me maybe some educated guesses, with your experience with it, what would cause GC to occur, and what I should try to avoid/look out for. Surely there's some 'good practice guidance' when working with PM? (i.e. what actions would/could cause excess GC?)

If worse comes to worse I'll definitely see how best to send it over, but in the meantime I could be on the look out for cases where I may be causing it and with your help investigate it myself.

Thanks Alex!

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Consistent GarbageCollection Spike...Yikes
« Reply #3 on: September 04, 2013, 10:03:35 PM »
Well we try to eliminate unnecessary garbage collection when we find it, so nothing jumps to mind - if it did we'd fix it :) But profiling outside of the editor is a big one, since there is logging and other stuff that happens in the editor that could cause garbage collection.

But I'll poke around using your breakdown as a guide and try to repro something here...

SteveB

  • Playmaker Newbie
  • *
  • Posts: 29
Re: Consistent GarbageCollection Spike...Yikes
« Reply #4 on: September 04, 2013, 10:05:57 PM »
I'm doing iOS builds, so would remote profiling be sufficient? That way yea we can best remove the editor from this to be certain.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Consistent GarbageCollection Spike...Yikes
« Reply #5 on: September 04, 2013, 10:15:23 PM »
Yes, that would work.

SteveB

  • Playmaker Newbie
  • *
  • Posts: 29
Re: Consistent GarbageCollection Spike...Yikes
« Reply #6 on: September 04, 2013, 10:38:41 PM »
Oooookay now we're getting somewhere...

...profiling off the iPhone5, PlayMaker.Update() never goes above 16% Total and GC doesn't budge from 0.6kb.

This was far more informative and I should've known better. I put my trust a bit too much into editor profiling. :D

Thanks Alex!

(P.S. You're missing Physics.Linecast from your Physics Actions  :o)

SteveB

  • Playmaker Newbie
  • *
  • Posts: 29
Re: Consistent GarbageCollection Spike...Yikes
« Reply #7 on: September 04, 2013, 10:47:21 PM »
Spoke too soon. It's still FAR better than it was in the editor, and probably won't be a problem but just to show you the worst of the spikes (which isn't horrible if you look at the graph)

What do you think? Look what I highlighted, AttributeHelperEngine.GetRequiredComponents()...

...I'm not sure what those are but they have the highest GC (with two iTween's and a GUI.Repaint coming in 2, 3 and 4th) and are all identical.

Thoughts?

SteveB

  • Playmaker Newbie
  • *
  • Posts: 29
Re: Consistent GarbageCollection Spike...Yikes
« Reply #8 on: September 04, 2013, 10:52:08 PM »
Also is it safe to assume each PlayMaker.Update() corresponds to an individual FSM on an GameObject, or all of an GO's FSM's? Or are they unrelated to GO's or individual FSM's? (I have 11 FSM's over 6 GO's).

Thanks again I know its late haha. :D

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Consistent GarbageCollection Spike...Yikes
« Reply #9 on: September 04, 2013, 11:40:08 PM »
Yeah, each PlayMaker.Update is an individual FSM.

Strange, PlayMaker doesn't call AttributeHelperEngine.GetRequiredComponents(). Poking around a bit, it's an internal UnityEngine method, so my guess is it's called internally on MonoBehaviours and is outside our control... but I'll ping Unity just in case there's something we can do about it...

SteveB

  • Playmaker Newbie
  • *
  • Posts: 29
Re: Consistent GarbageCollection Spike...Yikes
« Reply #10 on: September 05, 2013, 12:37:48 AM »
Cool I'd be curious to hear what might be happening...

...and just to be perfectly clear the only reason this started was that odd spike I get when editor profiling. It was significant enough to warrant some investigating, but otherwise everything is performing rather marvelously. I'm interested in what could be happening in my case but one way or the other it wouldn't be the end of the world. I'm quite pleased with PlayMaker and how quickly I've been able to progress. :D

Thanks Alex



Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Consistent GarbageCollection Spike...Yikes
« Reply #11 on: September 05, 2013, 08:35:57 PM »
Cool! Glad you're enjoying PlayMaker :)

I'm going to mark this solved for now. I'll report back any info I get from Unity...

SteveB

  • Playmaker Newbie
  • *
  • Posts: 29
Re: [SOLVED] Consistent GarbageCollection Spike...Yikes
« Reply #12 on: September 05, 2013, 08:38:51 PM »
Copy that.

Thanks Alex :)