perf(library): send the track list as a dictionary-encoded column table
GetTracks answered with one JSON object per track: 20.5 MB at 26k tracks, ~350 bytes a row of repeated key names, four cover URLs that are identical across an album, and the album, artist and genre strings repeated on every track. Encoding it was ~170 MB of transient Go allocation, and parsing it the WebView's memory peak. GetTrackTable replaces it: one array per column, every repeated string stored once and sent as an index, genre lists interned, and only the fields the Tracks view reads. LastPlayed and the three larger cover tiers are left to the details dialog, which now fetches whole tracks by path. Each row still goes through trackFromRow, so this is an encoding of the one projection, not a second one. 167 bytes a track against 929 in the test library; a Go test holds it under a quarter of the object encoding, and a Vitest test reads the Go columns and the generated Track interface and fails if they drift. An empty library is now an empty table rather than the "no tracks in library" error the old binding returned. Closes #281
This commit is contained in:
1 parent
4a9fe1d207
commit
7a1412383f
42 files changed
+1011
-275
No files matched your search
@@ -96,6 +96,36 @@ export async function callBinding<T = unknown>(
|
||||
) as Promise<T>;
|
||||
}
|
||||
|
||||
/** A library track as the specs use it: the path and its names. */
|
||||
export interface LibraryTrack {
|
||||
FilePath: string;
|
||||
TrackName: string;
|
||||
Album: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Every track in the library, in the order the backend lists them.
|
||||
*
|
||||
* The list arrives as a columnar `TrackTable` since #281 (repeated
|
||||
* strings sent once, as indexes into `strings`), so it cannot be read
|
||||
* as an array of tracks any more. This reads the three columns the
|
||||
* specs use; `frontend/src/utils/track-table.ts` is the real decoder.
|
||||
*/
|
||||
export async function libraryTracks(page: Page): Promise<LibraryTrack[]> {
|
||||
const t = await callBinding<{
|
||||
strings: string[];
|
||||
filePath: string[];
|
||||
trackName: number[];
|
||||
album: number[];
|
||||
}>(page, 'library.Library.GetTrackTable', [0]);
|
||||
|
||||
return (t.filePath ?? []).map((FilePath, i) => ({
|
||||
FilePath,
|
||||
TrackName: t.strings[t.trackName[i]!] ?? '',
|
||||
Album: t.strings[t.album[i]!] ?? '',
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* The binding calls the *app* made, newest last, as `pkg.Type.Method`.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user