2D Toolkit Forum
2D Toolkit => Support => Topic started by: drkucho on March 15, 2015, 02:00:01 pm
-
hello, i am optimising my code to avoid all unnecessary allocations, there was a lot of it generated on tk2d cause i was calling animation by string name of the clip for example, all the big allocation went away when getting all clips at start and calling Play with the tk2dSpriteAnimationClip
but still there is an small amount of alloc happening , this time seems to be related to Attach Point code?
(http://s27.postimg.org/vt4n2spqr/Screen_Shot_2015_03_15_at_14_42_01.png)
as you see right below the highlighted line there is a Object.get_name() , don't know why is that, i am not calling clips by name anymore and don't think sprite attach point uses the names of the sprites/clips ...?
the allocation is not much for just one sprite but i need hundreds of them in my scene so any idea how to get rid of it?
-
It looks like gameObject.name now allocates memory, hooray.
Only way I can think off is to create a dictionary with objects & strings.
-
not sure to understand, are you suggesting i should create a dictionary or that you would rewrite SpriteAttachPoints code with a dictionary?
i just thought that might be one of those cases that it allocates only if you run it from editor, i spent several hours after a 0.5k allocation on GetComponent and then i found on the net explanation for it, it only happens in editor and only when the component is not found , the allocation is to be able to display the error message as far as i understood, i made the test profiling the built and indeed it does not happen , i will try this with the AttachPoint , hopefully it's a similar case and won't happen in a build.
-
get_name suggets its the .name property thats firing this. I assumed you're getting this every frame hence the suggestion to cache the object name somewhere to avoid the allocation. But if it isn't happening per frame, why even bother? Its a tiny allocation.
Also, its completely pointless grabbing samples in the editor, so many things skew the readings.
-
well the thing is i am not asking for any object name , i might be skip something but i have reviewed my code so many times and the is no asking for anything with a name
its not happening every frame but every few frames and its going to be on every character in the game
this is the suspicious code
if (goodClip != anim.CurrentClip || main.CurrentFrame != anim.CurrentFrame){
anim.Sprite.SetSprite(goodClip.frames[frameToPlay].spriteId);
}
goodClip is --> private var goodClip:tk2dSpriteAnimationClip;
anim and main are both tk2dSpriteAnimator
-
That isn't the code that is asking the name, the code is in tk2dSpriteAttachPoint as the profiler shows. Anyway, its pointless caring about this if it doesn't happen in runtime. If it really does happen at runtime, then the dictionary should solve it.
-
if it is tk2dSpriteAttachPoint then you mean to create the dictionary in tk2dSpriteAttachPoint , so modifying your code?
-
Yes
-
im reading your code, sorry i am not good reading other ppl code and mostly if it is C , but if i am reading it ok ,you search for the right attach point to update for its name , you even suggested the dictionary in a comment
// A dictionary would be ideal here, but could end up in an indeterminate state due to
// user deleting things at runtime. Hopefully the user won't have that many attach points
// that a linear search becomes an issue
i don't plan to delete attach points at runtime so , is this search what i need to change?
-
First thing - are you 100% sure this is happening at runtime? The comment is unrelated.
-
i guess that is a yes but , right, thanks for reminding that, will profile the build