Skip to content

perf(ShaderView): pause render loop while app is backgrounded - #25

Merged
blazejkustra merged 1 commit into
mainfrom
feat/pause-on-background
Jun 28, 2026
Merged

perf(ShaderView): pause render loop while app is backgrounded#25
blazejkustra merged 1 commit into
mainfrom
feat/pause-on-background

Conversation

@blazejkustra

Copy link
Copy Markdown
Owner

What

The requestAnimationFrame render loop kept running after the app was backgrounded, churning frames against an offscreen (and often transiently invalid) surface — wasting battery/GPU and, since #22, silently swallowing per-frame errors.

This tracks AppState in ShaderView and gates the render-loop effect on it:

  • On a background transition, appActive flips false → the effect's existing cleanup (the cancelled token) tears the loop down.
  • On return to the foreground, the effect re-runs and starts a fresh loop.

We pause only on a true background state — iOS inactive (app-switcher peek, notification pulldown) keeps running to avoid flicker on brief foreground interruptions.

Why this approach

It reuses the loop's existing teardown machinery (the per-run cancelled synchronizable) instead of adding a separate cross-runtime pause/resume channel, so there's no new state to keep in sync.

Verification (argent, iOS — iPhone 17)

  1. Banners screen animating.
  2. Home button → app backgrounded → loop torn down.
  3. Re-foreground → animation resumes smoothly (coin counter advanced, lightning/fireworks at new phases across consecutive frames) — no freeze, no blank canvas.

Files

  • src/components/ShaderView/index.tsx

The requestAnimationFrame render loop kept running after the app was
backgrounded, churning frames against an offscreen (and often transiently
invalid) surface — wasting battery/GPU and, since PR #22, silently
swallowing per-frame errors.

Track AppState in ShaderView and gate the render-loop effect on it. On a
'background' transition the effect's existing cleanup (the `cancelled`
token) tears the loop down; on return to the foreground the effect
re-runs and starts a fresh loop. We pause only on a true 'background'
state — iOS 'inactive' (app-switcher peek, notification pulldown) keeps
running to avoid flicker on brief foreground interruptions.

Verified on iOS: Banners screen animates, home-button background stops
the loop, and re-foregrounding resumes smooth animation with no freeze
or blank canvas.
@blazejkustra
blazejkustra merged commit 872ffc7 into main Jun 28, 2026
2 checks passed
@blazejkustra
blazejkustra deleted the feat/pause-on-background branch June 28, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant