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
@@ -58,15 +58,15 @@ func TestScan_FixtureLibraryLeavesNothingBehind(t *testing.T) {
|
||||
t.Skip("fixture library is empty; run make testdata")
|
||||
}
|
||||
|
||||
tracks, err := lib.GetTracks(0)
|
||||
table, err := lib.GetTrackTable(0)
|
||||
if err != nil {
|
||||
t.Fatalf("GetTracks: %v", err)
|
||||
t.Fatalf("GetTrackTable: %v", err)
|
||||
}
|
||||
|
||||
// One track per file: the projection cannot multiply rows, because
|
||||
// there is no join table left to multiply them.
|
||||
if int64(len(tracks)) != files {
|
||||
t.Errorf("GetTracks returned %d rows for %d files", len(tracks), files)
|
||||
if int64(len(table.FilePath)) != files {
|
||||
t.Errorf("GetTrackTable returned %d rows for %d files", len(table.FilePath), files)
|
||||
}
|
||||
|
||||
// Nothing shared outlives what refers to it.
|
||||
|
||||
Reference in new issue
Block a user