SimpMusic icon indicating copy to clipboard operation
SimpMusic copied to clipboard

Desktop: endless queue appends tracks one by one, each triggering a full queue reorder + log dump (UI stalls)

Open Me-xico opened this issue 2 months ago • 2 comments

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

  1. Settings → Endless queue ON (default).
  2. Start a radio from any song and wait for the queue to load 50, 100, 150+ tracks.
  3. 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 [...]

Me-xico avatar Sep 15 '26 14:09 Me-xico

I dug into this and can propose a fix, if the shape works for you.

What happens, step by step:

  1. loadMoreCatalog (JVM and Android handlers) appends a radio batch one track at a time through addMediaItemNotSet, in a for loop. The player cannot know 49 more are coming, so every addMediaItem fires a full onTimelineChanged: 50 events per batch instead of 1.

  2. Each event runs reorderShuffledQueue on Desktop-Player-Thread. That is a mapNotNull { 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 hits if (sorted.size != listTrack.size) return, so all of that work is thrown away.

  3. Each MpvPlayerAdapter.addMediaItem also launches clearPrecacheExceptCurrentInternal() + 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.

  4. 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 _controlState updates in one second, 50 recompositions.

  5. 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): MpvPlayerAdapter does one addAll, one shuffle-order rebuild, one timeline notification, one precache trigger; CrossfadeExoPlayerAdapter delegates to ExoPlayer's native addMediaItems.
  • loadMoreCatalog collects the GenericMediaItems in its loop (it already builds catalogMetadata) and appends once at the end; prepare()/playWhenReady only when the player was empty; one updateNextPreviousTrackAvailability().
  • reorderShuffledQueue checks 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.

Me-xico avatar Sep 16 '26 16:09 Me-xico

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!

maxrave-dev avatar Sep 21 '26 02:09 maxrave-dev