From 687650518e2a8931852141bd6bf267cf9b5cb8dc Mon Sep 17 00:00:00 2001 From: Honey Date: Fri, 26 Jun 2026 16:56:11 +0200 Subject: [PATCH] perf(web): defer lyrics prefetch so it doesn't slow playback start prefetchLyrics now fires ~1.5s after a song change instead of immediately, so the lrclib requests no longer compete with audio-stream buffering when a new track starts. Timer is cleared on rapid song changes. Co-Authored-By: Claude Opus 4.8 --- src/player/nowplaying.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/player/nowplaying.js b/src/player/nowplaying.js index 25242f2..0e2ee2a 100644 --- a/src/player/nowplaying.js +++ b/src/player/nowplaying.js @@ -100,6 +100,7 @@ export function switchNpTab(tab) { let _lyricsLines = []; let _lyricsSongId = null; let _lyricsLoadToken = 0; +let _prefetchTimer = null; const _lyricsCache = new Map(); // "artist|title" → result object (null = not found) const LYRICS_LOOKAHEAD_MS = 200; @@ -283,8 +284,11 @@ export function onNpSongChange(songId) { _lyricsLines = []; const content = document.getElementById('np-lyrics-content'); if(content) content.innerHTML = ''; - // Warm the cache the moment the song changes, so the Lyrics tab opens instantly. - prefetchLyrics(S.queue.find(x => x.id === songId) || S.queue[S.qIdx]); + // Warm the cache shortly AFTER the track starts — deferred so the lyrics requests + // don't compete with the audio stream and delay playback start. + clearTimeout(_prefetchTimer); + const song = S.queue.find(x => x.id === songId) || S.queue[S.qIdx]; + _prefetchTimer = setTimeout(() => prefetchLyrics(song), 1500); if(S.npLyricsMode) _loadNpLyrics(songId); }