Skip to content

Feat/perf player UI optimizations#260

Merged
theovilardo merged 2 commits intomasterfrom
feat/perf-player-ui-optimizations
Oct 15, 2025
Merged

Feat/perf player UI optimizations#260
theovilardo merged 2 commits intomasterfrom
feat/perf-player-ui-optimizations

Conversation

@theovilardo
Copy link
Copy Markdown
Owner

No description provided.

This commit introduces several significant performance optimizations to the `UnifiedPlayerSheet` and its related components, focusing on reducing redundant compositions and deferring the rendering of expensive UI elements.

### Key Changes:

1.  **Deferred Composition (`DeferAt` and `DeferUntil`):**
    - New composable helpers `DeferAt` and `DeferUntil` have been introduced to delay the composition of UI subtrees until specific conditions are met (e.g., the player sheet is expanded beyond a certain fraction).
    - The `AlbumCarouselSection` and `PlayerSongInfo` (title/artist) are now only composed when the sheet expansion is greater than 12% and 20% respectively, significantly reducing initial composition cost.

2.  **Smoothed Progress Bar (`rememberSmoothProgress`):**
    - A new `rememberSmoothProgress` utility has been created to optimize the `WavyMusicSlider`.
    - It reduces the frequency of progress updates from the `ViewModel` (sampling at ~5 FPS) while using `animateFloatAsState` to create a visually smooth 60 FPS animation on the UI.
    - This drastically cuts down on recompositions triggered by frequent position updates, especially when the player is not fully expanded.

3.  **Conditional Marquee Text (`AutoScrollingTextOnDemand`):**
    - A new `AutoScrollingTextOnDemand` composable now checks if the text actually overflows its container *before* applying the expensive auto-scrolling marquee effect.
    - This prevents unnecessary performance overhead for shorter titles and artist names that don't need to scroll.

4.  **Neighboring Album Art Prefetching (`PrefetchAlbumNeighbors`):**
    - A new `PrefetchAlbumNeighbors` composable has been added, which proactively enqueues Coil image requests for the album art of songs adjacent to the current one in the queue.
    - This improves the user experience by ensuring that album art is likely already in the memory cache when the user swipes through the carousel.

5.  **General Code Cleanup:**
    - Removed a significant amount of dead and commented-out code from `UnifiedPlayerSheet.kt`.
    - Optimized ripple effects on player controls by reusing a single `Indication` instance.
This commit introduces significant performance optimizations and refactorings to the `UnifiedPlayerSheet`, focusing on animations, gesture handling, and rendering efficiency.

### Key Changes:

1.  **Optimized Player Sheet Animations:**
    *   Introduced a custom `rememberExpansionTransition` composable to manage animations tied to the sheet's expansion fraction. This replaces multiple `animate*AsState` calls with a more efficient, unified transition, reducing recompositions.
    *   The elevation (`playerAreaElevation`) and mini-player alpha (`miniAlpha`) are now driven by this unified transition.

2.  **Improved Drag Gesture Logic:**
    *   The vertical drag gesture handler (`detectVerticalDragGestures`) has been refactored for clarity and performance.
    *   It now uses `rememberUpdatedState` for values like `sheetCollapsedTargetY`, `sheetExpandedTargetY`, and `showPlayerContentArea`. This ensures the drag logic always references the latest values without needing to restart the gesture detector, making it more stable and efficient.

3.  **Conditional & Optimized `WavyMusicSlider`:**
    *   A new `isWaveEligible` parameter was added to `WavyMusicSlider`. This boolean, tied to the player sheet's expanded state, disables the wave effect and its underlying `rememberInfiniteTransition` when not visible. This significantly reduces CPU usage and invalidations when the player is collapsed.
    *   The wave drawing logic was improved to use `quadraticBezierTo` instead of `lineTo`, resulting in a much smoother sine wave animation with fewer drawing artifacts.

4.  **Album Art Prefetching Strategy:**
    *   Implemented two new composables, `PrefetchAlbumNeighbors` and `PrefetchAlbumNeighborsImg`, to proactively load album art for adjacent songs in the queue.
    *   Prefetching is triggered when the user starts expanding the player sheet or swipes the album carousel, ensuring cover art is ready before it comes into view and improving perceived performance.

5.  **General Code Cleanup:**
    *   Removed unused code, commented-out blocks, and unnecessary recomposition triggers throughout `UnifiedPlayerSheet.kt`.
    *   Added `key(song.id)` to items in `AlbumCarouselSection` to help Compose uniquely identify and manage items during recomposition.
@theovilardo theovilardo merged commit a0a7d24 into master Oct 15, 2025
@theovilardo theovilardo deleted the feat/perf-player-ui-optimizations branch October 16, 2025 18:04
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