Hello Guest

Author Topic: Sprite Attach Point small GC Alloc?  (Read 8521 times)

drkucho

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 72
  • Retro Arcade Freak
    • View Profile
    • Dr. Kucho!
Sprite Attach Point small GC Alloc?
« 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?



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?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Attach Point small GC Alloc?
« Reply #1 on: March 15, 2015, 02:17:38 pm »
It looks like gameObject.name now allocates memory, hooray.
Only way I can think off is to create a dictionary with objects & strings.

drkucho

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 72
  • Retro Arcade Freak
    • View Profile
    • Dr. Kucho!
Re: Sprite Attach Point small GC Alloc?
« Reply #2 on: March 15, 2015, 05:44:04 pm »
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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Attach Point small GC Alloc?
« Reply #3 on: March 15, 2015, 07:34:45 pm »
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.

drkucho

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 72
  • Retro Arcade Freak
    • View Profile
    • Dr. Kucho!
Re: Sprite Attach Point small GC Alloc?
« Reply #4 on: March 15, 2015, 09:50:11 pm »
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


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Attach Point small GC Alloc?
« Reply #5 on: March 15, 2015, 09:55:40 pm »
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.

drkucho

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 72
  • Retro Arcade Freak
    • View Profile
    • Dr. Kucho!
Re: Sprite Attach Point small GC Alloc?
« Reply #6 on: March 15, 2015, 10:06:34 pm »
if it is tk2dSpriteAttachPoint then you mean to create the dictionary in tk2dSpriteAttachPoint , so modifying your code?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Attach Point small GC Alloc?
« Reply #7 on: March 16, 2015, 12:44:58 am »
Yes

drkucho

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 72
  • Retro Arcade Freak
    • View Profile
    • Dr. Kucho!
Re: Sprite Attach Point small GC Alloc?
« Reply #8 on: March 16, 2015, 09:20:58 am »
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?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Attach Point small GC Alloc?
« Reply #9 on: March 16, 2015, 09:47:12 am »
First thing - are you 100% sure this is happening at runtime? The comment is unrelated.

drkucho

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 72
  • Retro Arcade Freak
    • View Profile
    • Dr. Kucho!
Re: Sprite Attach Point small GC Alloc?
« Reply #10 on: March 16, 2015, 12:42:11 pm »
i guess that is a yes but , right, thanks for reminding that, will profile the build