Skip to content

Optimize shuffle performance for large queues#594

Merged
theovilardo merged 2 commits intomasterfrom
codex/optimize-shuffle-algorithm-for-large-libraries
Dec 20, 2025
Merged

Optimize shuffle performance for large queues#594
theovilardo merged 2 commits intomasterfrom
codex/optimize-shuffle-algorithm-for-large-libraries

Conversation

@theovilardo
Copy link
Copy Markdown
Owner

Summary

  • implement Fisher-Yates-based shuffle helpers and anchored order generation to avoid heavy list copies
  • rebuild shuffled and original queues using existing media items off the main thread to reduce UI blocking and memory churn
  • preserve user position/current song while applying shuffle/unshuffle for large playlists

Testing

  • Not run (not requested)

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +2750 to +2752
withContext(Dispatchers.Main) {
player.setMediaItems(reorderedItems, safeIndex, positionMs)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Shuffle toggle replaces playlist without preparing or resuming

When toggling shuffle on/off, rebuildPlayerQueue calls player.setMediaItems(...) without a subsequent prepare()/play(). Player#setMediaItems resets the controller to an unprepared state, so an active session will stop playback and remain idle after shuffle/unshuffle. The prior implementation used move/add operations to preserve playback, and elsewhere in this file setMediaItems is followed by prepare()/play() (e.g., lines ~1734-1743), indicating preparation is required. Result: enabling or disabling shuffle during playback will silence the player until the user manually hits play.

Useful? React with 👍 / 👎.

- Remove redundant `kotlin.random.Random` imports in `PlayerViewModel.kt`.
- Introduce `headerPadding` to `QueueMiniPlayer` to dynamically adjust top padding.
- Remove redundant horizontal padding from the `QueueMiniPlayer` modifier in `QueueBottomSheet.kt`, centralizing padding logic within the component itself.
@theovilardo theovilardo merged commit 0d25dfa into master Dec 20, 2025
@udaign
Copy link
Copy Markdown

udaign commented Jan 15, 2026

much needed, good job!

@lostf1sh lostf1sh deleted the codex/optimize-shuffle-algorithm-for-large-libraries branch January 16, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants