Desktop: endless queue appends tracks one by one, each triggering a full queue reorder + log dump (UI stalls)
Duplicate Check
- [x] I confirm I searched for existing reports and found no duplicates.
Describe the Bug
On desktop (2.1.0, Linux), when a radio / endless queue loads its next batch of tracks, the UI freezes for several seconds (audio keeps playing). It gets worse as the queue grows and eventually the app never recovers.
From the logs, each single track appended to the queue triggers a full round of work in JvmMediaPlayerHandler:
onTimelineChanged: TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, items: N
Reordering shuffled queue: SIZE N, TITLE [...]
Reordered shuffled queue: SIZE N, TITLE [...]
Original queue: SIZE N, TITLE [... every title in the queue ...]
A batch of 50 tracks means 50 timeline events, 50 reorders of the whole queue and 50 log lines containing every title (the log alone went from ~90 to 4400 lines/minute, 15 MB per session in the journal). With 200 tracks queued that is ~10k operations in a burst on the UI thread. Per-second event counts during one batch: 50, 100, 150, 50. Disabling Endless queue in settings avoids it.
Suggested fix: append the batch as one operation (a single timeline event / one reorder per batch), and drop or downgrade the per-event dump of the whole queue.
Steps to Reproduce
- Settings → Endless queue ON (default).
- Start a radio from any song and wait for the queue to load 50, 100, 150+ tracks.
- UI stalls at each batch; the stall grows with the queue size.
Expected Behavior
Adding a batch of tracks to the queue should not block the UI.
App Version
2.1.0 (desktop, AppImage)
Android Version
N/A - CachyOS (Arch), GNOME Wayland
Device Model
Laptop, AMD Ryzen / Radeon 680M
Custom ROM
- [ ] I am using a custom ROM
Custom ROM Name (if applicable)
No response
Screenshots (optional)
No response
Log / Error Details
Excerpt (titles shortened), 51 identical rounds in the same second:
Inserted song: Self Aware
onTimelineChanged: TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, items: 0
Reordering shuffled queue: SIZE 0, TITLE []
Reordered shuffled queue: SIZE 0, TITLE []
Original queue: SIZE 1, TITLE [Self Aware]
onTimelineChanged: TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, items: 0
...
Original queue: SIZE 51, TITLE [...]
...
Original queue: SIZE 201, TITLE [...]
I dug into this and can propose a fix, if the shape works for you.
What happens, step by step:
-
loadMoreCatalog(JVM and Android handlers) appends a radio batch one track at a time throughaddMediaItemNotSet, in aforloop. The player cannot know 49 more are coming, so everyaddMediaItemfires a fullonTimelineChanged: 50 events per batch instead of 1. -
Each event runs
reorderShuffledQueueonDesktop-Player-Thread. That is amapNotNull { listTrack.firstOrNull { ... } }, i.e. player size × queue size string compares: on a 200-track queue 40k compares per event, 2M per batch. It then builds three log lines with every title in the queue (150 lines of 200 titles per batch), and during the batch it always hitsif (sorted.size != listTrack.size) return, so all of that work is thrown away. -
Each
MpvPlayerAdapter.addMediaItemalso launchesclearPrecacheExceptCurrentInternal()+triggerPrecachingInternal(): the precached mpv handles are released and recreated, and their stream URLs re-extracted, once per appended track. 50 handle teardown/create cycles per batch, on the same single thread. -
That thread serializes every player command, so play/pause/next from the UI queue behind the backlog. On the UI side,
updateNextPreviousTrackAvailability()is called per track too: 50_controlStateupdates in one second, 50 recompositions. -
The cost grows with the queue: step 2 is O(n·m), so each next batch is worse (measured per-second event counts on my queue: 50, 100, 150 as it grew to 200), until it never recovers.
Proposed change, all in core:
MediaPlayerInterface.addMediaItems(items):MpvPlayerAdapterdoes oneaddAll, one shuffle-order rebuild, one timeline notification, one precache trigger;CrossfadeExoPlayerAdapterdelegates to ExoPlayer's nativeaddMediaItems.loadMoreCatalogcollects theGenericMediaItems in its loop (it already buildscatalogMetadata) and appends once at the end;prepare()/playWhenReadyonly when the player was empty; oneupdateNextPreviousTrackAvailability().reorderShuffledQueuechecks the sizes before building anything, and logs sizes instead of titles.
Queue content and order are unchanged; only how many times the work runs. One behavioural difference to state: precache starts once at the end of the batch instead of restarting per track.
If this is fine with you I'll open the PR on core. I can reproduce and verify on Desktop; Android would be compile-only on my side.
Fixed on dev in 8a033b39, which bumps core to maxrave-dev/core@3f94cc6.
- Tracks are still appended one at a time, but each timeline event is now cheap: the queue reorder is a map lookup instead of a nested search over the whole queue, and it logs sizes only instead of every title.
- Radio queues now keep 100 played tracks behind the current one, and drop the oldest in a single batched removal once the history passes 150, so the queue no longer grows without bound.
Ships in v2.2.0. Thanks for the detailed report!