From b6035cb3ad2fc99a7631df4f581a0e5ce1e5e067 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Wed, 8 Apr 2026 10:27:19 -0600 Subject: [PATCH] perf(prefetch): increase cache depth to 5 tracks, 2 concurrent - V2_PREFETCH_COUNT: 2 -> 5 (cache ~2 min ahead) - V2_MAX_CONCURRENT_PREFETCH: 1 -> 2 (overlap downloads) - V2_PREFETCH_LOOKAHEAD: 10 -> 15 (find more Qobuz tracks) Combined with parallel CMAF segments from previous commit, this keeps the cache well ahead of playback. The sliding window re-triggers on every track play, so the 5-track buffer advances continuously through the queue. cc --- src-tauri/src/commands_v2.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/commands_v2.rs b/src-tauri/src/commands_v2.rs index ab7da71f4..d6337b2a5 100644 --- a/src-tauri/src/commands_v2.rs +++ b/src-tauri/src/commands_v2.rs @@ -2258,14 +2258,20 @@ pub async fn v2_start_system_browser_oauth( // ==================== Prefetch (V2) ==================== -/// Number of Qobuz tracks to prefetch (not total tracks, just Qobuz) -const V2_PREFETCH_COUNT: usize = 2; +/// Number of Qobuz tracks to prefetch (not total tracks, just Qobuz). +/// Higher values keep more upcoming tracks in cache for instant playback. +/// CMAF segment downloads are ~24s per Hi-Res track, so 5 tracks means +/// the cache stays ~2 minutes ahead of playback. +const V2_PREFETCH_COUNT: usize = 5; -/// How far ahead to look for tracks to prefetch (to handle mixed playlists) -const V2_PREFETCH_LOOKAHEAD: usize = 10; +/// How far ahead to look for tracks to prefetch (to handle mixed playlists +/// with local/offline tracks interspersed with Qobuz tracks) +const V2_PREFETCH_LOOKAHEAD: usize = 15; -/// Maximum concurrent prefetch downloads -const V2_MAX_CONCURRENT_PREFETCH: usize = 1; +/// Maximum concurrent prefetch downloads (track-level, not segment-level). +/// 2 tracks downloading simultaneously keeps the cache filling while +/// one download is in its cooldown/decryption phase. +const V2_MAX_CONCURRENT_PREFETCH: usize = 2; lazy_static::lazy_static! { /// Semaphore to limit concurrent prefetch operations