Skip to content

Rive drains battery in the background on Android #413

Open

Description

@Nezz

Submission checklist

  • I have confirmed the issue is present in the latest version of @rive-app/react-native
  • I have searched the documentation and forums and could not find an answer
  • I have searched existing issues and this is not a duplicate

Description

On Android with the new backend, once an app has loaded a Rive file it keeps a Choreographer frame callback posted on every vsync for the rest of the process. Even when every Rive view is paused or unmounted, the main thread wakes 60 times a second. This is not a big deal while the app running normally, but it keeps happening when the app is backgrounded.

Here's what my Claude found, but you probably know better:

Two loops are responsible. Both have been there since the new backend landed in 0.5.0 (#134):

  1. The view's render loop never stops while paused. In RiveReactNativeView.kt#L172-L178,
    a paused view with nothing to redraw just refreshes lastFrameTimeNs and posts itself again.
    Every other path posts again too (L221).
    The loop only stops when the view is disposed.
  2. The CommandQueue is polled on every vsync for the life of the process. Once the shared worker
    exists, HybridRiveFileFactory.startPolling
    posts a frame callback that calls pollMessages() and re-posts itself forever, even when no Rive
    view is mounted.

Previous working version

No response

Reproduction steps / code

https://github.com/Nezz/expo-repro/tree/repro/RivePausedFrames

bun install
npx expo run:android --variant release
scripts/run.sh 3

Then press Home and count frame callbacks for 10 s:

adb shell atrace -t 10 view | grep -c "B|$(adb shell pidof com.adamys.exporepro)|Choreographer#doFrame"

That gives ~600. The same app before it loads a Rive file gives 0.

Upload your reproduction files / stack trace

No response

Source .riv / .rev file

No response

Screenshots / video

No response

@rive-app/react-native version

0.5.4

Platform

Android only

React Native version

0.86.3

React Native environment info

Expo setup

Yes — Expo prebuild / EAS Build

Expo SDK version (if applicable)

No response

iOS device & OS version (if applicable)

57.0.27

Android device & OS version (if applicable)

Android Emulator — API Level 36 (Medium Phone, 60 Hz)

Additional context

New Android backend, release build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    androidbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions