Skip to content

autoplay (in 4.0.0-canary.13) is FAR more processor-intensive; it should not use requestAnimationFrame on every call #669

@nmassey

Description

@nmassey

Describe the bug

  1. when autoplay is enabled, rather than using timers, the code in play() runs as quickly as it can on every animation frame. This uses a LOT of processor (see video screengrab below) and ultimately battery life
  2. autoplay now has different timings: subsequent scrolls do not wait for the scrollAnimationDuration time

How to fix

I recommend reverting:

Unfortunately, this PR seems to have a few issues:

  1. primarily, running this check code in requestAnimationFrame() over and over again is really awful for processor usage / performance / battery usage. Using setTimeout (or perhaps some other method for a timer?) would be better
  2. since lastTimestampRef.current = currentTimestamp is called immediately in play() after when calling next() and prev(), it restarts the countdown too soon (rather than waiting for the scroll to complete)

I'm not fully sure what #536 is intended to fix, but unfortunately it seems to add a few issues. ☹️

To Reproduce

<Carousel
  autoPlay={true}
  autoPlayInterval={1000}
  scrollAnimationDuration={1000}

Screengrab videos

4.0.0-alpha.12 (old code, better performance)

Notice that the CPU time stays low. It increases a little bit during scroll, but otherwise it stays low.

Also, see that it's almost exactly 2 seconds between transitions (1 second for the scrollAnimationDuration plus 1 second for autoPlayInterval)

Screen.Recording.2024-09-11.at.12.26.58.mov

4.0.0-canary.13 (includes #536, worse performance)

Notice that the CPU time stays high. 😮

Also, notice that the time between transitions is not the same as in previous versions.

Screen.Recording.2024-09-11.at.12.23.33.mov

Versions:

  • expo: v50.0.20
  • react: v18.2.0
  • react-native: v0.73.6
  • react-native-reanimated: v3.6.2
  • react-native-reanimated-carousel: v4.0.0-canary.13
  • react-native-gesture-handler: v2.14.1

Smartphone:

  • Device: iPhone 15 Pro Simulator
  • OS: 17.5

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions