Skip to content

Media library: list albums with a grouped tag query when mtime isn't needed - #670

Open
Sciencentistguy wants to merge 1 commit into
ncmpcpp:masterfrom
Sciencentistguy:media-library-faster-album-listing
Open

Sciencentistguy wants to merge 1 commit into
ncmpcpp:masterfrom
Sciencentistguy:media-library-faster-album-listing

Conversation

@Sciencentistguy

Copy link
Copy Markdown

In the two column and album-only media library modes, building the album list takes about 0.8s on my library (~48k songs), as they build their album list by fetching the whole database with listallinfo and reducing it on the client.

This changes it to request the tuples directly instead:

list album group artist group date

What changed

  • New Connection::GetListGrouped() that sends list <tag> group <tag>....
  • MediaLibrary::update() uses it for the two column and album-only modes. The old code is moved unchanged into listAlbumsWithMTime().
  • configure.ac now needs libmpdclient >= 2.12 (for mpd_search_add_group_tag). The group argument also needs MPD >= 0.19.

Behaviour notes

  • media_library_sort_by_mtime = yes still uses listallinfo, since mtimes aren't available from the grouped query. That mode isn't any faster.
  • Results should match the old code: songs without the primary tag are still skipped, and date is only used when media_library_albums_split_by_date is on. One difference is that a song with several album or date values now gives one entry per combination, where before only the first value was used.

Testing

I built a copy that computed both lists on every load and compared them. The albums were identical for two column and album-only mode, with media_library_albums_split_by_date on and off. I haven't tried MPD older than 0.19, or a library with songs that lack the primary tag (mine has none).

Timings

I benchmarked the two code paths with hyperfine, using a small standalone program that sends the same command and builds the same std::map (default settings, both return 10,488 entries). Times include process start and connecting.

Command Mean wall time
listallinfo (before) 826.1 ± 4.5 ms
list album group artist group date (after) 19.3 ± 1.0 ms (42.9x faster)

MPD 0.24.15 over a local unix socket, libmpdclient 2.24, 47,645 songs. Inside ncmpcpp itself I measured about 15ms against 860ms.

g++ -O2 -std=c++17 albums.cpp -o albums -lmpdclient
MPD_HOST=/path/to/socket hyperfine --warmup 3 --runs 30 -N './albums listallinfo' './albums grouped'

I used Claude Code to help with this change.

…eded

In the two column and album-only modes the whole database was fetched with
listallinfo and reduced to (tag, album, date) tuples on the client. With
~48k songs this takes about 0.85s, and the response is large enough to
overflow mpd's default max_output_buffer_size when the mode is toggled
repeatedly.

Ask mpd for the same tuples with `list album group <tag> [group date]`
instead, which takes ~15ms. The per-song listing is still used when
media_library_sort_by_mtime is enabled, as modification times aren't
available from the grouped query.

This requires libmpdclient >= 2.12 and MPD >= 0.19 for the group argument.
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