pmndrs / react-spring

✌️ A spring physics based React animation library
http://www.react-spring.dev/
MIT License
28.19k stars 1.19k forks source link

Serious performance problems in Firefox using examples #767

Closed martinbroos closed 1 week ago

martinbroos commented 5 years ago

🐛 Bug Report

When using firefox (tested on mac / windows) the react spring animations become extremely slow and make the complete page no longer useable. At first I thought it was a problem in my code but this also happens when visiting the react spring example page. Works fine in chrome and safari.

To Reproduce

Steps to reproduce the behavior:

Visit https://www.react-spring.io/docs/hooks/examples in Firefox.

Tested with Firefox Quantum 68.0.1 (64-bits) on mac

Expected behavior

Regular framerate

Environment

But as stated this is also happening on the react spring page.

martinbroos commented 5 years ago

After some more research it looks like it only get's slow in firefox when mapping over transitions / trails inside the render function. For example my app uses 2 useTransitions to create a slider, this will get slow. One transition slides the content, and the other will fade out the background video.

    const slideVideoTransitions = useTransition(
        currentSlideIndex,
        item => item,
        videoTransformationProperties // uses opacity
    );
const slideContentTransitions = useTransition(
        currentSlideIndex,
        item => item,
        transitionProperties // uses translate3d
    );
            {slideVideoTransitions.map(({ item, props, key }) => {
                const currentSpotlight = spotlights[item];

                return (
                    <animated.div
                        key={key}
                        style={props}
                    >
...video component
                    </animated.div>
                );
            })}
            {slideContentTransitions.map(({ item, props, key }) => {
                const currentSpotlight = spotlights[item];
                return (
                    <animated.div
                        key={key}
                        style={props}
                        className="hero__slide"
                    >
... slide component
                    </animated.div>
                );
            })}

When using springs that will only set props inside the render this has no impact on the performance.

When looking at the react-spring examples:

Slow in firefox: https://codesandbox.io/embed/8zx4ppk01l

Fast in firefox: https://codesandbox.io/embed/rj998k4vmm https://codesandbox.io/embed/01yl7knw70

https://codesandbox.io/embed/vqpqx5vrl0

The last one does map over transitions so this is where I get lost, but hopefully this will give some more context.

martinbroos commented 5 years ago

When looking at the Goo Blob demo it renders pretty fast when making your window small but using it on fullscreen or retina display it get's slow.

In my app the speed also improves when using a smaller viewport. Could it be that animating translate and rendering video in firefox has performance issues on large screens?

joshuaellis commented 3 years ago

Doesn't GSAP have performance issues with Firefox and it's down to the browser not the library?

joshuaellis commented 1 week ago

I'm not sure this is something wrong with react-spring after reviewing again, three years later. No one else reported this either so I think we can consider this closed :)