mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
9925771a86
* 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.
144 lines
4.0 KiB
TypeScript
144 lines
4.0 KiB
TypeScript
import { useSyncExternalStore } from 'react';
|
|
import {
|
|
isLiveHistoryPin,
|
|
liveOverlayItemValue,
|
|
} from './formatLiveOverlayItems';
|
|
import type { PerfLiveSnapshot } from './perfLiveStore';
|
|
|
|
const HISTORY_MS = 60_000;
|
|
const EMPTY_VALUES: readonly number[] = [];
|
|
const EMPTY_SAMPLES: readonly Sample[] = [];
|
|
|
|
export type PerfLiveSample = {
|
|
readonly at: number;
|
|
readonly value: number;
|
|
};
|
|
|
|
type Sample = PerfLiveSample;
|
|
|
|
const series = new Map<string, Sample[]>();
|
|
const valueCache = new Map<string, { source: Sample[]; values: readonly number[] }>();
|
|
const listeners = new Set<() => void>();
|
|
|
|
function emit(): void {
|
|
listeners.forEach(fn => fn());
|
|
}
|
|
|
|
function trim(samples: Sample[], now: number): Sample[] {
|
|
const cutoff = now - HISTORY_MS;
|
|
let start = 0;
|
|
while (start < samples.length && samples[start].at < cutoff) start += 1;
|
|
return start > 0 ? samples.slice(start) : samples;
|
|
}
|
|
|
|
function appendSample(id: string, value: number, at: number): boolean {
|
|
if (!Number.isFinite(value)) return false;
|
|
const existing = series.get(id) ?? [];
|
|
const last = existing[existing.length - 1];
|
|
if (last && last.at === at && last.value === value) return false;
|
|
const appended =
|
|
last && last.at === at
|
|
? [...existing.slice(0, -1), { at, value }]
|
|
: [...existing, { at, value }];
|
|
const next = trim(appended, at);
|
|
series.set(id, next);
|
|
valueCache.delete(id);
|
|
return true;
|
|
}
|
|
|
|
export function recordPerfLiveHistory(id: string, value: number, at = Date.now()): void {
|
|
if (appendSample(id, value, at)) emit();
|
|
}
|
|
|
|
/** Record pinned live samples for one poll tick; returns the new last-recorded timestamp. */
|
|
export function syncPerfLiveHistoryFromPoll(
|
|
pins: Iterable<string>,
|
|
live: PerfLiveSnapshot,
|
|
lastRecordedAt: number,
|
|
): number {
|
|
if (!live.cpu?.supported || live.updatedAt <= 0 || live.updatedAt === lastRecordedAt) {
|
|
return lastRecordedAt;
|
|
}
|
|
let changed = false;
|
|
for (const pin of pins) {
|
|
if (!isLiveHistoryPin(pin)) continue;
|
|
const value = liveOverlayItemValue(pin, live);
|
|
if (value != null && appendSample(pin, value, live.updatedAt)) changed = true;
|
|
}
|
|
if (changed) emit();
|
|
return live.updatedAt;
|
|
}
|
|
|
|
export function getPerfLiveHistoryClock(ids: Iterable<string>): number {
|
|
let latest = 0;
|
|
for (const id of ids) {
|
|
const samples = series.get(id);
|
|
const last = samples?.[samples.length - 1];
|
|
if (last && last.at > latest) latest = last.at;
|
|
}
|
|
return latest;
|
|
}
|
|
|
|
export function getPerfLiveHistorySamples(id: string): readonly PerfLiveSample[] {
|
|
const now = Date.now();
|
|
let samples = series.get(id) ?? [];
|
|
const trimmed = trim(samples, now);
|
|
if (trimmed.length !== samples.length) {
|
|
samples = trimmed;
|
|
series.set(id, samples);
|
|
}
|
|
return samples.length === 0 ? EMPTY_SAMPLES : samples;
|
|
}
|
|
|
|
export function getPerfLiveHistory(id: string): readonly number[] {
|
|
const now = Date.now();
|
|
let samples = series.get(id) ?? [];
|
|
const trimmed = trim(samples, now);
|
|
if (trimmed.length !== samples.length) {
|
|
samples = trimmed;
|
|
series.set(id, samples);
|
|
}
|
|
if (samples.length === 0) return EMPTY_VALUES;
|
|
|
|
const cached = valueCache.get(id);
|
|
if (cached && cached.source === samples) return cached.values;
|
|
|
|
const values: readonly number[] = samples.map(s => s.value);
|
|
valueCache.set(id, { source: samples, values });
|
|
return values;
|
|
}
|
|
|
|
export function clearPerfLiveHistory(id?: string): void {
|
|
if (id) {
|
|
series.delete(id);
|
|
valueCache.delete(id);
|
|
} else {
|
|
series.clear();
|
|
valueCache.clear();
|
|
}
|
|
emit();
|
|
}
|
|
|
|
export function subscribePerfLiveHistory(cb: () => void): () => void {
|
|
listeners.add(cb);
|
|
return () => listeners.delete(cb);
|
|
}
|
|
|
|
export function usePerfLiveHistorySamples(id: string): readonly PerfLiveSample[] {
|
|
return useSyncExternalStore(
|
|
subscribePerfLiveHistory,
|
|
() => getPerfLiveHistorySamples(id),
|
|
() => EMPTY_SAMPLES,
|
|
);
|
|
}
|
|
|
|
export function usePerfLiveHistory(id: string): readonly number[] {
|
|
return useSyncExternalStore(
|
|
subscribePerfLiveHistory,
|
|
() => getPerfLiveHistory(id),
|
|
() => EMPTY_VALUES,
|
|
);
|
|
}
|
|
|
|
export const PERF_LIVE_HISTORY_MS = HISTORY_MS;
|