Micro-profiler TweenService Delays

Hi all,

I am having a performance issue in my new game, and while I’ve tracked down the issue in the micro-profiler, I’m not sure how to go about dealing with it.

Essentially, once players open on the order of 1000-2000 eggs in my game, performance starts to tank and frame-skips start occuring. In the microprofiler, I can see the the PreRender task is taking something up to 100ms, this mainly being caused by TweenService taking a huge amount of time to resolve. This happens while opening the eggs, but what’s strange is that it also continues to happen every few frames after the egg opening animations are finished.

I know this is likely to be something specific in my own code that is causing it, but does anybody have any ideas what the issue might be? I am cleaning up all of my tweens, and destroying them/the objects they are attached to once they are completed. I also don’t have any infinitely looping tweens that could be causing this issue. A memory leak I also find unlikely, as that would cause increased memory usage (which I haven’t noticed an appreciable amount of), rather than every 3-4 frames a huge TweenService computation being performed.

None of my scripts are taking up more than 2% in the script performance window either, if that makes any difference.

Screenshots below:

Normal frame (haven’t opened any eggs):

After opening ~1000 eggs (frames still aren’t dropping but you can see a large load):

Post 2,000 eggs (a good frame):

Post 2,000 eggs (a bad frame)

You can see the for some reason TweenService is taking a huge amount of time to complete, despite (to the best of my knowledge) there being no active tweens. Does anybody have any ideas what might be causing this?

To clarify, your opening ~1000 eggs at a single time etc?

I am giving myself around 20 pets per second, using the normal egg opening code just sped up. I am not giving them all at once, and while usually there are animations that play alongside this they are all currently disabled (they use TweenService so I thought they might be the issue, but it seems to persist).

GIving myself 2000 pets with command does not seem to cause any issues though, so I’m not sure what it could be!
It’s likely to be some quirk or mistake I’ve made in my own code, but I thought I’d post here anyway in case someone has an insight to offer.

Ok I’ve found the issue, it was a strongly referenced table keeping old frames around and they were being tweened between two colours. Dumb mistake, and is now fixed.