Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS animation architectural design for optimal performance

The performance gains of the GreenSock animation engine are pretty dramatic.

What underlying architectural decisions and trade-offs is this library making to achieve such gains? In particular, what is this engine doing different than jQuery animate?

like image 780
jedierikb Avatar asked Sep 14 '12 16:09

jedierikb


People also ask

Does animation affect performance?

Animation can help make a site feel faster and responsive, but animations can also make a site feel slower and janky if not done correctly. Responsive user interfaces have a frame rate of 60 frames per second (fps).

Is JavaScript good for animation?

But, for more complex or advanced effects, JavaScript is a better tool. It goes without saying that using JavaScript to create animations is more challenging than using CSS. Nevertheless, JavaScript can handle things that CSS can't.

Do animations slow down website?

Too much motion can slow down the loading of a web page. Too many animations prevent visitors from knowing which parts of the page to focus on. Website animation doesn't always translate well to mobile, which leads to poor experiences.

Is Gsap the best animation library?

GSAP is yet another powerful animation library built on HTML5 and JavaScript. It ensures that animations run smoothly on modern web browsers and HTML5 solutions by binding multiple animation properties and eliminating browser bugs.


1 Answers

great answer here from the folks at greensock:

  1. Use highly optimized JavaScript across the board (this entails many things like using linked lists, local variables, quick lookup tables, inlining code, bitwise operators, leveraging prototypes instead of recreating functions/variables for each instance, etc.)
  2. Engineer the structure of the platform so that it lends itself very well to high-pressure situations, minimizing function calls and making sure things are gc-friendly.
  3. Make updates in a single update loop that's driven by requestAnimationFrame, only falling back to setTimeout() if necessary.
  4. Cache some important values internally for faster updates.
  5. For CSS transforms, we calculate matrix values and construct either a matrix() or matrix3d() when there's any rotation or skewing because our tests showed that it was faster.

More here: http://forums.greensock.com/topic/9346-how-does-greensock-perform-better-than-other-solutions-for-animation/#entry37777

like image 81
jedierikb Avatar answered Sep 20 '22 16:09

jedierikb