Skip to content

What actions and LB's cause Garbage Collect?

Ask for help here ;)

What actions and LB's cause Garbage Collect?

Postby RichMakeGame » 05 Sep 2012, 15:40

Hi there, I'm running into some performance spikes in my code, and I'd like to understand better what's happening and how to avoid it.

I've run the deep profiler, and when I pick a spike and follow the trail of the highest cpu use (usually a vizio update or fixed update) it normally leads to a GC collect.

this is happening after I've spawned objects and nothing is created or destroyed at the time, which leads me to believe things I'm doing in vizio are creating garbage. So I'd like to know what to look out for. An example which I am guessing may contribute to the problem- I use 'vector 3 create' fairly often. Does this make a new vector each frame which gets created anew and causes cleanup of the 'dead' values? What about 'get value'- does calling that every frame have any impact on garbage?

in short, what actions and circumstances should I avoid when trying to minimize garbage collection?

cheers!
-Rich
RichMakeGame
 
Posts: 49
Joined: 16 Feb 2012, 20:30

Re: What actions and LB's cause Garbage Collect?

Postby RichMakeGame » 05 Sep 2012, 21:47

I've been doing some (very rough) tests with my game and the profiler.

I'm assuming that GC alloc is the data passed to garbage collector (I don't see it in the docs?) and so higher numbers here mean more frequent collects?

of my commonly used blocks here are the highest GC allocs in my project:

vector 3 multiply
vector constructor ( is that create vector 3?)
vector 3 scale
float multiply
transform forward/up/right
get velocity

does that sound right / make sense? should I look at ways to cut down using these LBs?
RichMakeGame
 
Posts: 49
Joined: 16 Feb 2012, 20:30

Re: What actions and LB's cause Garbage Collect?

Postby Neodrop » 09 Sep 2012, 14:29

This nodes don't produced any extra garbage itself. It's happend when too many Variables is used by your code during one frame. Try to decrease the quantity of your Variables in your code.
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: What actions and LB's cause Garbage Collect?

Postby RichMakeGame » 12 Sep 2012, 13:17

Hi Neo- are you sure? my experiments with the deep profiler show some blocks add to CG alloc.

here is one graph in an empty scene, with only one vector 3 create LB:
as you can see it seems to be generating 20 bytes garbage, and the number increases by 20 with added create vector LB's

Image
RichMakeGame
 
Posts: 49
Joined: 16 Feb 2012, 20:30

Re: What actions and LB's cause Garbage Collect?

Postby holyjewsus » 12 Sep 2012, 16:33

I think this is to be expected, as you are creating a new vector, I believe that in unity the vector 3 is a struct, and a value type and in some sense immutable, so unity creates a new vector, the old one needs to be garbage collected.

Does this not happen if you use c#? have you tried deep profiling regular code using a vector 3 create function?
holyjewsus
 
Posts: 390
Joined: 08 Apr 2011, 00:58

Re: What actions and LB's cause Garbage Collect?

Postby holyjewsus » 16 Sep 2012, 00:28

Yeah, I'm not sure my last comment was correct, seems my c# tests don't create this garbage...hmmm I noticed the random range blocks also create garbage.
holyjewsus
 
Posts: 390
Joined: 08 Apr 2011, 00:58

Re: What actions and LB's cause Garbage Collect?

Postby holyjewsus » 16 Sep 2012, 06:25

It seems each update activator will cause 16bytes of garbage collection every frame just by itself, not attached to any other blocks.
holyjewsus
 
Posts: 390
Joined: 08 Apr 2011, 00:58

Re: What actions and LB's cause Garbage Collect?

Postby Neodrop » 16 Sep 2012, 16:35

Well, it's not so, as I see from the Profiler screen above. Update activator create no one dinamic data and because of that, produce no garbage. Also as any other activators (as I remember).
But every Get/Set variables value actions, produce a bit.
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: What actions and LB's cause Garbage Collect?

Postby holyjewsus » 16 Sep 2012, 16:59

well then I guess something I did caused a bug... I can post the graph and profiler.
holyjewsus
 
Posts: 390
Joined: 08 Apr 2011, 00:58

Re: What actions and LB's cause Garbage Collect?

Postby holyjewsus » 16 Sep 2012, 19:55

Image

this graph is sitting on an object named actor, there is nothing but an update activator in it.

this is the deep profile.

Image
holyjewsus
 
Posts: 390
Joined: 08 Apr 2011, 00:58

Re: What actions and LB's cause Garbage Collect?

Postby Neodrop » 19 Sep 2012, 12:42

Ok. I have removed 1 dinamic variable from this method. May be it'll decrease this 16 bites (but I don't test it yet). Thank you.
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: What actions and LB's cause Garbage Collect?

Postby RichMakeGame » 21 Sep 2012, 13:37

I'm starting to wonder if it is a universe related issue?

this document mentions structs are not allocated on the heap- so why should struct operations create garbage allocations? :
http://docs.unity3d.com/Documentation/M ... ement.html

also in this thread: http://forum.unity3d.com/threads/140673 ... sset-Store
I read the quote:
"Keep in mind that value types (such as structs) do not allocate on the heap and therefore do not live in the land of the garbage collector. You could could call "new Vector3()" hundreds of thousands of times per frame and not cause a single garbage collection"
this seems to contradict my test scene where each new vector created added 20bytes

If it turns out to be an unavoidable part of universe itself I think it's very important to know about it
RichMakeGame
 
Posts: 49
Joined: 16 Feb 2012, 20:30

Re: What actions and LB's cause Garbage Collect?

Postby beddnollop » 15 May 2015, 19:47

Thank you for good communication.
beddnollop
 
Posts: 13
Joined: 15 May 2015, 09:33


Return to HELP!!!

Who is online

Registered users: No registered users