Skip to content

fix: stabilize carousel cpu perf on idle#968

Merged
utkarshdalal merged 1 commit intoutkarshdalal:masterfrom
xXJSONDeruloXx:fix/carousel-idle-bootstrap
Mar 22, 2026
Merged

fix: stabilize carousel cpu perf on idle#968
utkarshdalal merged 1 commit intoutkarshdalal:masterfrom
xXJSONDeruloXx:fix/carousel-idle-bootstrap

Conversation

@xXJSONDeruloXx
Copy link
Copy Markdown
Contributor

@xXJSONDeruloXx xXJSONDeruloXx commented Mar 22, 2026

snapshot layout on idle to prevent redraws at hz rate which causes high cpu usage on render thread and lock up after extended idle on center focused item.

Summary by cubic

Stabilized the library carousel by snapshotting layout metrics and computing the centered item from a consistent source. This removes flicker and incorrect centering during initial load and scrolling.

  • Bug Fixes
    • Added CarouselLayoutSnapshot and a produceState + snapshotFlow(...).distinctUntilChanged() to capture viewport center/span, visible item centers, and first/last visible indexes.
    • Replaced direct listState.layoutInfo reads with the snapshot to avoid transient values causing jitter.
    • Normalized calculations using the snapshot’s viewport span and indices, fixing fallback selection and first-card edge offset.

Written for commit 222f298. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Improved carousel performance by refactoring internal layout calculations to reduce redundant computations and minimize unnecessary state updates.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 22, 2026

📝 Walkthrough

Walkthrough

This change refactors LibraryCarouselPane to centralize layout calculations by introducing a CarouselLayoutSnapshot data structure. It replaces scattered direct reads of listState.layoutInfo with a single produced snapshot via produceState/snapshotFlow, reducing redundant layout access and applying distinctUntilChanged() to minimize reactive churn.

Changes

Cohort / File(s) Summary
Carousel Layout Snapshot Refactoring
app/src/main/java/app/gamenative/ui/screen/library/components/LibraryCarouselPane.kt
Introduced CarouselLayoutSnapshot data structure to consolidate layout info. Updated centeredIndex calculation, selection/focus logic, and per-item transform calculations to use snapshot fields (visibleItemCenters, viewportCenter, viewportSpan, firstVisibleItemIndex, lastVisibleIndex) instead of directly accessing listState.layoutInfo. Added distinctUntilChanged() to reduce reactive updates.

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly Related PRs

  • feat(library): carousel layout #797: Initial refactoring of LibraryCarouselPane internals that introduced the snapshot-based layout calculation pattern replacing direct listState.layoutInfo reads.

Poem

🥕 A carousel spins with grace refined,
Snapshots dance, no lags to find,
Layout reads now sing as one,
Reactive churn—now undone!
Hop-hop-hooray, this refactor's fun! 🎠

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main optimization: stabilizing carousel CPU performance during idle states by introducing a snapshot-based approach to replace repeated layout reads.

✏️ 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

@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.

No issues found across 1 file

@xXJSONDeruloXx xXJSONDeruloXx changed the title fix: stabilize carousel layout snapshot fix: stabilize carousel cpu perf on idle Mar 22, 2026
@utkarshdalal utkarshdalal merged commit e4ac93f into utkarshdalal:master Mar 22, 2026
3 checks passed
@xXJSONDeruloXx xXJSONDeruloXx deleted the fix/carousel-idle-bootstrap branch March 22, 2026 11:11
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