perf(playlist): use $state.raw for tracks to eliminate proxy bloat
$state() creates deep reactive proxies for every object in the array. With 2000 tracks, each background batch reassignment triggered proxy creation for all existing + new objects, growing quadratically. $state.raw() only tracks the reference — no deep proxying. Combined with a fast path in displayTracks that skips the full copy/interleave when there are no local tracks, search, or custom sort.
This commit is contained in:
1 parent
33eb990a6c
commit
8f1cc735a7
1 file changed
+7
-4
@@ -206,7 +206,7 @@
|
||||
}: Props = $props();
|
||||
|
||||
let playlist = $state<Playlist | null>(null);
|
||||
let tracks = $state<DisplayTrack[]>([]);
|
||||
let tracks = $state.raw<DisplayTrack[]>([]);
|
||||
let localTracks = $state<PlaylistLocalTrack[]>([]);
|
||||
let localTracksMap = $state<Map<number, PlaylistLocalTrack>>(new Map());
|
||||
let hasLocalTracks = $derived(localTracks.length > 0);
|
||||
@@ -1200,9 +1200,12 @@
|
||||
|
||||
// Filtered and sorted tracks (merged Qobuz + local by position)
|
||||
let displayTracks = $derived.by(() => {
|
||||
// Build merged list by interleaving based on position
|
||||
// Local tracks have explicit playlist_position
|
||||
// Qobuz tracks fill positions not occupied by local tracks
|
||||
// Fast path: no local tracks, no search, default sort → skip copy entirely
|
||||
if (localTracks.length === 0 && !searchQuery.trim() && sortBy === 'default') {
|
||||
return tracks;
|
||||
}
|
||||
|
||||
// Full path: interleave with local tracks, filter, sort
|
||||
const result: DisplayTrack[] = [];
|
||||
|
||||
// Create a map of local track positions
|
||||
|
||||
Reference in new issue
Block a user