Skip to content

fix: Pause and resume PerformanceHudView with lifecycle#1463

Merged
utkarshdalal merged 2 commits into
utkarshdalal:masterfrom
joshuatam:fix/pause-PerformanceHudView-on-sleep
May 21, 2026
Merged

fix: Pause and resume PerformanceHudView with lifecycle#1463
utkarshdalal merged 2 commits into
utkarshdalal:masterfrom
joshuatam:fix/pause-PerformanceHudView-on-sleep

Conversation

@joshuatam
Copy link
Copy Markdown
Contributor

@joshuatam joshuatam commented May 21, 2026

Description

Integrates the PerformanceHudView with the screen's lifecycle to automatically pause its updates when the screen is in the background (ON_PAUSE) and resume them when it returns to the foreground (ON_RESUME).

This change conserves resources and prevents unnecessary activity when the application is not actively displayed.

Recording

None

Type of Change

  • Bug fix
  • Performance / stability improvement
  • Compatibility improvements
  • Other (requires prior approval)

Checklist

  • If I have access to #code-changes, I have discussed this change there and it has been green-lighted. If I do not have access, I have still provided clear context in this PR. If I skip both, I accept that this change may face delays in review, may not be reviewed at all, or may be closed.
  • This change aligns with the current project scope (core functionality, stability, or performance). If not, it has been explicitly approved beforehand.
  • I have attached a recording of the change.
  • I have read and agree to the contribution guidelines in CONTRIBUTING.md.

Summary by cubic

Pause PerformanceHudView when the screen goes to the background and resume it on return to foreground to cut unnecessary updates and save resources.

  • Bug Fixes
    • Hooked into the screen lifecycle with DisposableEffect and LifecycleEventObserver (pause on ON_PAUSE, resume on ON_RESUME) and synced the initial state with the current lifecycle.
    • Added pause()/resume() with an isPaused flag; guarded startUpdates() in onAttachedToWindow; removed the observer on dispose.
    • Raised CPU/GPU temperature logs from verbose to debug for better visibility.

Written for commit a54c8cd. Summary will update on new commits. Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Performance HUD now reliably pauses and resumes metric updates with the app lifecycle, reducing resource use when the app is inactive and avoiding unnecessary restarts when the HUD is not visible.
  • Chores
    • Adjusted HUD logging verbosity for clearer diagnostics during performance monitoring.

Review Change Stack

Integrates the PerformanceHudView with the screen's lifecycle to automatically
pause its updates when the screen is in the background (ON_PAUSE) and
resume them when it returns to the foreground (ON_RESUME).

This change conserves resources and prevents unnecessary activity when
the application is not actively displayed.
@joshuatam joshuatam requested a review from utkarshdalal as a code owner May 21, 2026 03:18
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5c706b99-1484-4e6b-acdf-4a7a0189acec

📥 Commits

Reviewing files that changed from the base of the PR and between 1788e0e and a54c8cd.

📒 Files selected for processing (2)
  • app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.kt
  • app/src/main/java/app/gamenative/ui/widget/PerformanceHudView.kt

📝 Walkthrough

Walkthrough

Adds pause/resume methods to PerformanceHudView that gate its metric-update loop and wires those methods to XServerScreen lifecycle events so the HUD is paused on ON_PAUSE and resumed on ON_RESUME.

Changes

Performance HUD Pause/Resume Lifecycle Control

Layer / File(s) Summary
PerformanceHudView pause/resume implementation
app/src/main/java/app/gamenative/ui/widget/PerformanceHudView.kt
Introduces isPaused flag to gate update coroutine execution. Adds public pause() and resume() to toggle the flag and manage the update coroutine. onAttachedToWindow() starts updates only when not paused. CPU/GPU temperature logs changed to debug.
XServerScreen lifecycle wiring
app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.kt
Adds a DisposableEffect that registers a LifecycleEventObserver to call hud.pause() on ON_PAUSE and hud.resume() on ON_RESUME, and unregisters the observer on disposal.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • utkarshdalal/GameNative#1406: Overlaps with updates to PerformanceHudView temperature logging and diagnostic changes.
  • utkarshdalal/GameNative#853: Both add lifecycle-driven pause/resume behavior in XServerScreen (this PR targets PerformanceHudView; the other targets the renderer).

Suggested reviewers

  • utkarshdalal

Poem

🐰 The HUD takes a gentle nap when screens go dim,
It wakes with a twitch when the lifecycle's prim,
Paused with a hop, resumed with a cheer,
Metrics breathe softly when the path is clear.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: integrating PerformanceHudView with lifecycle management to pause/resume updates.
Description check ✅ Passed The description includes a clear explanation of changes, aligns with template structure, and has most checklist items completed. However, the 'I have attached a recording' checkbox is unchecked while the Recording section shows 'None', which is acceptable given the nature of the change.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.kt`:
- Around line 1471-1494: The LifecycleEventObserver registered inside
DisposableEffect (involving performanceHudView, lifecycleOwner and observer)
only reacts to future ON_PAUSE/ON_RESUME events; to fix, immediately inspect
lifecycleOwner.lifecycle.currentState after creating hud and call hud.pause() if
state.isAtLeast(Lifecycle.State.STARTED) is false (or call hud.resume() if state
is resumed/started) so the HUD is synchronized with the current lifecycle; keep
the existing observer registration and onDispose removal and ensure you only
call pause()/resume() when hud is non-null.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e811883a-cacc-4323-b17d-ec8e70e5a2cd

📥 Commits

Reviewing files that changed from the base of the PR and between 9350ccf and 1788e0e.

📒 Files selected for processing (2)
  • app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.kt
  • app/src/main/java/app/gamenative/ui/widget/PerformanceHudView.kt

Comment thread app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.kt
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.kt
@utkarshdalal utkarshdalal merged commit 4a6e79d into utkarshdalal:master May 21, 2026
3 checks passed
@joshuatam joshuatam deleted the fix/pause-PerformanceHudView-on-sleep branch May 21, 2026 14:30
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.

2 participants