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:
cucadmuh
2026-05-29 04:40:31 +03:00
committed by GitHub
parent 839c438a6d
commit 9925771a86
67 changed files with 5298 additions and 1043 deletions
@@ -0,0 +1,130 @@
import { useMemo, useRef } from 'react';
import type { PerfLiveSample } from '../../utils/perf/perfLiveHistory';
import { PERF_LIVE_HISTORY_MS } from '../../utils/perf/perfLiveHistory';
type SparklineKind = 'cpu' | 'memory';
interface Props {
samples: readonly PerfLiveSample[];
kind: SparklineKind;
now: number;
windowMs?: number;
width?: number;
height?: number;
}
function sampleX(at: number, now: number, windowMs: number, width: number): number {
const age = now - at;
const ratio = 1 - age / windowMs;
return Math.max(0, Math.min(width, ratio * width));
}
function sparklinePaths(
samples: readonly PerfLiveSample[],
now: number,
windowMs: number,
width: number,
height: number,
min: number,
max: number,
): { line: string; area: string } {
if (samples.length === 0) return { line: '', area: '' };
const range = Math.max(max - min, 1e-6);
const toY = (value: number) => height - ((value - min) / range) * (height - 2) - 1;
const sorted = [...samples].sort((a, b) => a.at - b.at);
if (sorted.length === 1) {
const x = sampleX(sorted[0].at, now, windowMs, width);
const y = toY(sorted[0].value);
const x0 = Math.max(0, x - 6);
const line = `M${x0.toFixed(2)},${y.toFixed(2)} L${x.toFixed(2)},${y.toFixed(2)}`;
const area = `${line} L${x.toFixed(2)},${height} L${x0.toFixed(2)},${height} Z`;
return { line, area };
}
const points = sorted.map(sample => ({
x: sampleX(sample.at, now, windowMs, width),
y: toY(sample.value),
}));
const line = points
.map((point, index) => `${index === 0 ? 'M' : 'L'}${point.x.toFixed(2)},${point.y.toFixed(2)}`)
.join(' ');
const first = points[0];
const last = points[points.length - 1];
const area = `${line} L${last.x.toFixed(2)},${height} L${first.x.toFixed(2)},${height} Z`;
return { line, area };
}
function scale(samples: readonly PerfLiveSample[], kind: SparklineKind): { min: number; max: number } {
if (samples.length === 0) return { min: 0, max: 1 };
const values = samples.map(sample => sample.value);
const minVal = Math.min(...values);
const maxVal = Math.max(...values);
if (kind === 'cpu') {
return { min: 0, max: Math.max(100, maxVal * 1.1) };
}
const pad = Math.max((maxVal - minVal) * 0.08, maxVal * 0.02, 1);
return { min: Math.max(0, minVal - pad), max: maxVal + pad };
}
function stableScale(
samples: readonly PerfLiveSample[],
kind: SparklineKind,
peakRef: { current: number },
): { min: number; max: number } {
const raw = scale(samples, kind);
if (kind === 'cpu') return raw;
if (raw.max > peakRef.current) peakRef.current = raw.max;
return { min: 0, max: Math.max(peakRef.current, raw.max) };
}
/** Compact 1-minute sparkline for perf overlay CPU / memory pins. */
export default function PerfOverlaySparkline({
samples,
kind,
now,
windowMs = PERF_LIVE_HISTORY_MS,
width = 132,
height = 22,
}: Props) {
const peakRef = useRef(1);
const { path, areaPath } = useMemo(() => {
const bounds = stableScale(samples, kind, peakRef);
const paths = sparklinePaths(samples, now, windowMs, width, height, bounds.min, bounds.max);
return { path: paths.line, areaPath: paths.area };
}, [samples, kind, now, windowMs, width, height]);
const latest = samples.length > 0 ? samples[samples.length - 1]?.value : null;
return (
<svg
className={`perf-overlay-sparkline perf-overlay-sparkline--${kind}`}
width={width}
height={height}
viewBox={`0 0 ${width} ${height}`}
aria-hidden="true"
>
<rect
className="perf-overlay-sparkline__track"
x={0}
y={0}
width={width}
height={height}
rx={3}
/>
{areaPath && <path className="perf-overlay-sparkline__fill" d={areaPath} />}
{path && (
<path className="perf-overlay-sparkline__line" d={path} vectorEffect="non-scaling-stroke" />
)}
<title>
{latest == null
? `${kind === 'cpu' ? 'CPU' : 'Memory'} (1 min)`
: kind === 'cpu'
? `CPU ${latest.toFixed(1)}% (1 min)`
: `Memory ${latest.toFixed(1)} MB (1 min)`}
</title>
</svg>
);
}