mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 15:25:46 +00:00
feat(browse,cover,perf): lazy catalogs, cover pipeline, and Performance Probe (#890)
* fix(cover): per-server cache stats and cover pipeline perf probe Stop count_cached_cover_ids from borrowing sibling bucket counts so Settings progress no longer attributes one server's disk cache to another. Add cover pipeline queue stats (ui ensure queue, ui vs lib HTTP/WebP semaphores) to Performance Probe overlay, with clearer ui/lib labels. * fix(browse): stabilize in-page infinite scroll and cap cover memory caches Extract useInpageScrollSentinel for album grids and song lists so sentinel reconnects do not spam loadMore during scroll. Harden useAlbumBrowseData with sync loading refs, tighter root margin, and hasMore termination when dedupe adds nothing. Pause middle-priority cover work during SQL pagination and bound diskSrc/resolve/ensure tail maps on long cold-cache sessions. * refactor(browse): unify in-page infinite scroll hooks and sentinel UI Extract shared transport (viewport ref, async pagination guards, client slice) and InpageScrollSentinel so Albums, New Releases, Artists, and song lists use one pagination pattern instead of duplicated IntersectionObserver wiring. * fix(browse): prioritize album SQL pagination over cover ensures Pause the entire webview ensure pump during grid page fetches, resume after SQL settles, add cover-queue backpressure before load-more, and re-probe the sentinel when pagination finishes so cold-cache scroll does not stall. * fix(browse): unblock covers, SQL spawn_blocking, and pagination retry Pair grid-pagination hold begin/end on stale fetches, resume the ensure pump after SQL, retry load-more when the cover backlog drains while the sentinel stays visible, and run album browse SQL on spawn_blocking so Tokio stays responsive during library_advanced_search. * feat(browse): All Albums client-slice scroll on local index (Artists-style) Load the filtered catalog once from SQLite when the library index is ready, then grow the visible grid with useClientSliceInfiniteScroll instead of offset SQL pagination per scroll. Network-only servers keep page mode. * fix(browse): lazy local catalog chunks instead of full 50k SQL fetch All Albums slice mode now loads 200 albums first, shows the grid immediately, then appends catalog chunks in the background as the user scrolls. Avoids the blocking library_advanced_search that hung the app on large libraries. * fix(browse): keep album covers loading during active grid scroll Pass high ensure priority and the in-page scroll root to AlbumCard on All Albums, stop pausing cover traffic for background catalog chunks, and never trim high-priority ensure jobs from the queue during scroll bursts. * fix(cover): viewport priority tiers and unstick ensure invoke pump All Albums uses IO-driven high/middle instead of blanket high; release only on unmount so scroll-ahead jobs are not dropped on reprioritize. Ensure queue shares one Rust flight per cover id, attaches duplicate waiters without consuming invoke slots, and times out wedged calls. Warm the first viewport slice on large grids; acquire CPU permits before spawn_blocking in cover_cache to avoid blocking-thread deadlocks. * fix(cover): wire in-page scroll root on New Releases and Lossless grids AlbumCard IO uses the same viewport id as VirtualCardGrid so cover ensure priority tracks visible in-page rows like All Albums. * fix(browse): lazy local artist catalog in 200-row chunks Replace runLocalBrowseAllArtists bulk fetch with paginated local-index chunks so large libraries do not hang on open; preserve text search, starred, letter filter, and client-slice scroll behavior. * feat(perf): add RSS and thread CPU groups to Performance Probe Extend performance_cpu_snapshot with process RSS (psysonic + WebKit children) and in-process thread CPU breakdown. Classify tokio-rt-worker and tokio-* workers separately from glib, audio/pipewire, reqwest, and other misc threads (Linux /proc only). * feat(perf): redesign Performance Probe with tabs, pins, and overlay layout Split the probe into Monitor (live metric cards, per-metric overlay pins, corner and opacity controls) and Toggles (diagnostic tree). Share live polling via perfLiveStore; label analysis/cover pipeline blocks in the HUD. * feat(perf): overlay sparklines, macOS CPU/memory, and sync fixes Add 1-minute pinned-metric sparklines with right-aligned growth and a shared poll clock. Enable macOS performance snapshots via sysinfo. Fix overlay infinite loop from unstable history snapshots, bar/sparkline tick jitter, and probe bar rescale flicker. * docs: CHANGELOG and credits for PR #890 * perf(probe): scoped CPU poll, adjustable interval, lazy thread groups Read only psysonic + WebKit children instead of the full process table; macOS uses sysctl host CPU and refreshes cached child PIDs. Add 0.5–10s poll slider (default 2s). Collect /proc thread groups only when the Monitor section is open or a thread metric is pinned. * feat(perf): three-way overlay mode switch (off / FPS / pinned) Add Monitor control for overlay visibility: hidden, FPS-only, or pinned metrics from Monitor. Live CPU poll runs only in pinned mode with live pins.
This commit is contained in:
@@ -47,6 +47,49 @@ pub struct CoverCacheStatsDto {
|
||||
pub entry_count: u64,
|
||||
}
|
||||
|
||||
/// Live cover HTTP / WebP-encode slots — mirrors analysis pipeline probe shape.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CoverPipelineQueueStatsDto {
|
||||
pub http_max: u32,
|
||||
pub http_active: u32,
|
||||
pub cpu_ui_max: u32,
|
||||
pub cpu_ui_active: u32,
|
||||
pub cpu_backfill_max: u32,
|
||||
pub cpu_backfill_active: u32,
|
||||
pub library_backfill_http_max: u32,
|
||||
pub library_backfill_http_active: u32,
|
||||
pub library_backfill_pass_running: bool,
|
||||
}
|
||||
|
||||
fn sem_active(sem: &Semaphore, max: u32) -> u32 {
|
||||
max.saturating_sub(sem.available_permits() as u32)
|
||||
}
|
||||
|
||||
pub(crate) fn cover_pipeline_queue_stats(
|
||||
cache: &CoverCacheState,
|
||||
backfill: Option<&backfill_worker::CoverBackfillWorker>,
|
||||
) -> CoverPipelineQueueStatsDto {
|
||||
let (library_backfill_http_max, library_backfill_http_active, library_backfill_pass_running) =
|
||||
backfill
|
||||
.map(backfill_worker::CoverBackfillWorker::pipeline_http_stats)
|
||||
.unwrap_or((0, 0, false));
|
||||
CoverPipelineQueueStatsDto {
|
||||
http_max: COVER_HTTP_CONCURRENCY as u32,
|
||||
http_active: sem_active(&cache.http_sem, COVER_HTTP_CONCURRENCY as u32),
|
||||
cpu_ui_max: COVER_CPU_UI_CONCURRENCY as u32,
|
||||
cpu_ui_active: sem_active(&cache.cover_cpu_ui_sem, COVER_CPU_UI_CONCURRENCY as u32),
|
||||
cpu_backfill_max: COVER_CPU_BACKFILL_CONCURRENCY as u32,
|
||||
cpu_backfill_active: sem_active(
|
||||
&cache.cover_cpu_backfill_sem,
|
||||
COVER_CPU_BACKFILL_CONCURRENCY as u32,
|
||||
),
|
||||
library_backfill_http_max,
|
||||
library_backfill_http_active,
|
||||
library_backfill_pass_running,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CoverCacheEnsureArgs {
|
||||
@@ -204,14 +247,15 @@ impl CoverCacheState {
|
||||
};
|
||||
|
||||
let dir_bg = dir.clone();
|
||||
let cover_cpu_sem_bg = cover_cpu_sem.clone();
|
||||
let tiers_bg = tiers_now.clone();
|
||||
let cpu_permit = cover_cpu_sem
|
||||
.clone()
|
||||
.acquire_owned()
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
let (mut wrote_requested, fresh_tiers) = tauri::async_runtime::spawn_blocking(
|
||||
move || -> Result<(bool, Vec<(u32, PathBuf)>), String> {
|
||||
let rt = tokio::runtime::Handle::current();
|
||||
let _permit = rt
|
||||
.block_on(cover_cpu_sem_bg.acquire())
|
||||
.map_err(|e| e.to_string())?;
|
||||
let _cpu_permit = cpu_permit;
|
||||
let img = match source {
|
||||
CoverSource::Image(i) => i,
|
||||
CoverSource::Bytes(b) => decode_image_bytes(&b)?,
|
||||
@@ -374,11 +418,11 @@ fn spawn_derive_remaining_tiers(
|
||||
guard.cpu_sem_for(args.library_bulk),
|
||||
)
|
||||
};
|
||||
let Ok(cpu_permit) = cover_cpu_sem.clone().acquire_owned().await else {
|
||||
return;
|
||||
};
|
||||
let written = tauri::async_runtime::spawn_blocking(move || -> Vec<(u32, PathBuf)> {
|
||||
let rt = tokio::runtime::Handle::current();
|
||||
let Ok(_permit) = rt.block_on(cover_cpu_sem.acquire()) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let _cpu_permit = cpu_permit;
|
||||
let mut fresh = Vec::new();
|
||||
for tier in tiers_bg {
|
||||
if tier_exists(&dir, tier).is_some() {
|
||||
@@ -400,23 +444,9 @@ fn spawn_derive_remaining_tiers(
|
||||
}
|
||||
|
||||
/// Entity dirs with canonical `800.webp` under `album/` and `artist/` (segment layout).
|
||||
/// Per-server only — must not borrow counts from sibling buckets (multi-server UI stats).
|
||||
pub(crate) fn count_cached_cover_ids(root: &Path, server_index_key: &str) -> i64 {
|
||||
let keyed = count_entities_with_canonical_tier(&cover_server_dir(root, server_index_key));
|
||||
if keyed > 0 {
|
||||
return keyed;
|
||||
}
|
||||
// Host alias / legacy bucket name — pick the best segment count among siblings.
|
||||
let Ok(entries) = std::fs::read_dir(root) else {
|
||||
return 0;
|
||||
};
|
||||
entries
|
||||
.flatten()
|
||||
.filter(|e| {
|
||||
e.path().is_dir() && e.file_name().to_string_lossy() != ".storage-layout"
|
||||
})
|
||||
.map(|e| count_entities_with_canonical_tier(&e.path()))
|
||||
.max()
|
||||
.unwrap_or(0)
|
||||
count_entities_with_canonical_tier(&cover_server_dir(root, server_index_key))
|
||||
}
|
||||
|
||||
pub(crate) fn dir_usage_for_server(root: &Path, server_index_key: &str) -> (u64, u64) {
|
||||
@@ -687,6 +717,19 @@ pub async fn cover_cache_stats_server(
|
||||
})
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn cover_cache_get_pipeline_queue_stats(
|
||||
app: AppHandle,
|
||||
) -> Result<CoverPipelineQueueStatsDto, String> {
|
||||
let st = state(&app)?;
|
||||
let guard = st.lock().await;
|
||||
let backfill = app.try_state::<Arc<backfill_worker::CoverBackfillWorker>>();
|
||||
Ok(cover_pipeline_queue_stats(
|
||||
&guard,
|
||||
backfill.as_ref().map(|w| w.as_ref()),
|
||||
))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn cover_cache_clear_server(
|
||||
app: AppHandle,
|
||||
@@ -979,10 +1022,26 @@ mod tests {
|
||||
|
||||
use super::decode_image_bytes;
|
||||
use super::disk::{cover_dir, tier_path};
|
||||
use super::{is_safe_index_key, merge_cover_bucket, rename_bucket_inner};
|
||||
use super::{count_cached_cover_ids, is_safe_index_key, merge_cover_bucket, rename_bucket_inner};
|
||||
use psysonic_core::cover_cache_layout::CANONICAL_PROGRESS_TIER;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[test]
|
||||
fn count_cached_cover_ids_is_per_server_bucket() {
|
||||
let root = fresh_tmpdir("count-per-server");
|
||||
let home = cover_dir(&root, "music.home.example", "album", "al-home");
|
||||
fs::create_dir_all(&home).unwrap();
|
||||
fs::write(
|
||||
home.join(format!("{CANONICAL_PROGRESS_TIER}.webp")),
|
||||
b"x",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(count_cached_cover_ids(&root, "music.home.example"), 1);
|
||||
assert_eq!(count_cached_cover_ids(&root, "music.other.example"), 0);
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disk_layout_paths() {
|
||||
let root = std::path::Path::new("/tmp/cover-test");
|
||||
|
||||
Reference in New Issue
Block a user