Skip to content

Leaner idle, heap and startup; lists that don't shrink on errors - #10

Merged
junaydirfan merged 1 commit into
masterfrom
perf-idle
Nov 24, 2026
Merged

junaydirfan merged 1 commit into
masterfrom
perf-idle

Conversation

@junaydirfan

Copy link
Copy Markdown
Owner

Efficiency pass, measured on a release build against a scratch copy of a real config/cache (Liked Songs: 3,953 songs, 110 playlists), Soloist backend, in tmux at 140×42. PSS from /proc/<pid>/smaps_rollup, wakeups = voluntary context switches over all threads.

before (v0.4.1) after
Wakeups idle (nothing playing) ~15 / min ~3 / min (Spotify's AP keepalive)
Wakeups paused 4 / 20 s 1 / 20 s
CPU idle / paused 0 0
CPU playing 0.20% 0.20%
PSS idle at start 17.9 MB 15.9 MB
PSS Liked Songs open, playing 23.0 MB 19.2 MB
PSS after skipping two songs 28.9 MB 18.7 MB
First frame (tmux) 542 ms ~55 ms
Binary 9.08 MB 6.49 MB

What changed

  • No health timer. The 15 s session.is_invalid() interval is gone. A dead connection is noticed (and reconnected, at most every 15 s) on the next key, event or 1 Hz playback tick. The wakeups left while idle are librespot answering Spotify's keepalive ping, about one round per minute.
  • Heap. Each decoded cover freed a few MB inside glibc's second arena. glibc's dynamic mmap threshold then raised the trim threshold, so malloc_trim couldn't hand that memory back (seen in malloc_info: 7.0 of 7.08 MB free, all in the top chunk). Setting M_MMAP_THRESHOLD once at start fixes the threshold. I also tried trimming inside the decode thread: no effect, so it isn't included.
  • Smart shuffle kept a full copy of the playing list (3,953 rows) to append 50 picks. They now live in their own recs list.
  • Image query. In tmux, and in terminals that don't answer, the query waited its 400 ms timeout plus 100 ms on every start. A terminal that didn't answer is now remembered in ~/.cache/trill/silent_terminals (keyed by TERM, TERM_PROGRAM, tmux and the terminal-specific env vars, re-asked after a week). The next start builds the same fallback picker the timeout would have given.
  • Partial failures. ext_meta turned a failed request into an empty map, and context_tracks skipped a failed page. Both silently dropped songs, and the shorter list was saved over the good disk copy. Failures now propagate: the copy on screen stays, and the status says it's the saved one.
  • Offline start. With no network, the cached-login failure was treated as a bad login and opened the browser. Now only an auth rejection re-logs in. A network error says "can't reach Spotify… your saved login is kept" and exits.
  • opt-level "s": −2.6 MB binary and −2 MB PSS. Cover decode (--debug-tint, 12 covers), re-sorting 3,953 rows and key-to-frame were the same within noise (10–19 ms both ways, mostly tmux polling).

Looked at, not changed

  • Row with Box<str> would go from 168 to 128 bytes, ~160 KB on 4k songs. That's under 1% of PSS, so it's not worth the churn.
  • librespot keeps ~16 idle TLS connections from parallel metadata requests (its hyper pool has no idle timer). That isn't configurable from trill.

Tested

  • cargo test, cargo clippy (0 warnings).
  • In tmux: start, open Liked Songs, play, skip, pause, smart-shuffle queue (✦ picks woven every 3 songs), w, sort cycling, offline start (unshare -rn).
  • Not tested: macOS/Windows (CI compile only), and the reconnect after a real network drop.

…shrink on errors

- No 15 s session health timer: a lost connection is noticed on the next key, event or
  second of playback. Idle wakeups drop from ~15 to ~3 a minute (what's left is Spotify's
  own keepalive), and paused from ~12 to ~3 a minute.
- A fixed glibc mmap threshold: each decoded cover raised the trim threshold, leaving ~7 MB
  of free heap resident. PSS after a few song changes: 28.9 MB -> 20.8 MB.
- Smart-shuffle picks live in their own list instead of a copy of the whole playing list
  (-1.6 MB of heap with Liked Songs playing).
- Terminals that don't answer the image query (tmux, ConPTY) are remembered for a week, so
  the first frame doesn't wait the 0.5 s timeout: 542 ms -> ~50 ms in tmux.
- A metadata request or page that still fails after librespot's retries fails the load,
  instead of dropping those songs and saving the shorter list over the good copy. A failed
  refresh says the saved copy is showing.
- Offline at start: say so and keep the saved login, instead of opening a browser login.
- opt-level "s": the binary goes from 9.1 MB to 6.5 MB and PSS by ~2 MB, with no
  measurable change in CPU, cover decoding or key-to-frame time.
@junaydirfan
junaydirfan merged commit 317f035 into master Nov 24, 2026
3 checks passed
@junaydirfan
junaydirfan deleted the perf-idle branch November 24, 2026 06:07
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