playMaker

Author Topic: Get many children without huge GC penalty?  (Read 2226 times)

joepalos

  • Playmaker Newbie
  • *
  • Posts: 28
Get many children without huge GC penalty?
« on: July 31, 2016, 03:03:23 PM »
Hi,

So far, to loop through a big number of children GameObjects (possibly thousands), I'm using the Get Next Child action.

In short, I get one of them, I do a check on it, if the check is positive I add the GameObject to an array, repeat.

The problem is that doing this on many children creates a huge halt in game processing (like 500ms) and triggers a 120MB garbage collector activity.

Is there a "correct" way to this, without this big penalty?

NOTE: Once they are in the array, processing them does not cause the penalty. It's the Get Next Child, Get Tag, Add To Array cycle that causes this.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get many children without huge GC penalty?
« Reply #1 on: August 01, 2016, 05:17:23 AM »
Hi,

 I think your problem is two fold.

1: instead of looping trhough children, you should experiment with sending a global event to all these children in one action ( send event), and then each children will have an FSM catching this and adding it self to the array if necessary ( could be a global array, or could be in a Manager Fsm that each child is aware of).

2: looping isn't costly, it's what you do inside the loop, so indeed it's one of the action you use that is the culltrip. So I would profile further and see what action specifically creates the issue.

Can you list all actions you use inside the loop?

How many Object do you go trhough to trigger a 120MG garbage collection?

Bye,

 Jean

joepalos

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Get many children without huge GC penalty?
« Reply #2 on: August 01, 2016, 02:47:34 PM »
I usually go through about 1500-3000 objects.

1: instead of looping trhough children, you should experiment with sending a global event to all these children in one action ( send event), and then each children will have an FSM catching this
In my experience even inactive FSMs (one empty start state) add too much overhead to have more than 1500 of them in a scene. And 1500 of them receiving a message at once would certainly cause stutters in the game.
2: looping isn't costly, it's what you do inside the loop
I've broken up the FSM in parts to separate the one causing the GC issues, and it's certainly the adding next and next and next GameObject to a GameObject variable many times that is causing this. In other words, overwriting a GameObject variable with the next GameObject very quickly.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get many children without huge GC penalty?
« Reply #3 on: August 10, 2016, 03:05:50 AM »
Hi,

 Can you name the actions you use in the loop, I'll have a look.

Bye,

 Jean