Jump to content
Search Community

Performance of conditional checks vs tweens with no change in value

shoey test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi sorry if this has been asked already it's kind of a hard question to search for.

 

I plan to have a pixi js scene of images for my website background where I'm often tweening images in and out of the scene, but in some scenarios tweening already offscreen images offscreen again so those tweens don't change any values. Do these unnecessary tweens affect performance? Is it better for performance to have conditional checks instead of 'no change in value' tweens?

 

I don't think I will have performance issues either way but I wonder if gsap already has something built-in that automatically optimizes 'no change tweens' so that they don't have any affect on performance even if there are a large amount of them triggered all at the same time.

 

Thanks.

Link to comment
Share on other sites

When a tween renders for the first time, that's when it records the starting/ending values and if they're the same (no change), it's skipped internally, yes. So, for example, if you try tweening to x:100 but x is already 100, it won't keep trying to set that value over and over again during the tween. But the tween itself will still run because other factors matter (like there could be an onComplete or onUpdate, plus if may need to take up space in a timeline, etc.) 

 

Does that answer your question? 

 

Even if GSAP didn't skip those parts, I highly doubt you'd ever notice a performance difference. It's super fast. Maybe if you literally had 50,000 tweens simultaneously running, you'd notice it. :)

 

Good luck with the project!

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...