hinto-janai / festival

Music player
https://festival.pm
MIT License
273 stars 5 forks source link

`Songs` tab is laggy #71

Open hinto-janai opened 11 months ago

hinto-janai commented 11 months ago

Version

Festival GUI v1.3.0

Bug

The Songs tab is very laggy.

Although the current code only displays the viewport (good), every single Song object is iterated through and processed (very bad).

Fix

Selectively index through the songs (e.g [start..end]) and only process and display those.

The issue is when a scrollbar is involved - "where" we are in the array must be accounted for depending on how far the scrollbar has scrolled.

The range (e.g 10 songs listed? 20 songs?) depends on sizing, resolution, etc - although this should be easy to find:

let total_rows = ui.height() / desired_row_height;

for song in songs[start..start + total_rows] {
    /* process and display songs */
}

Different sort orderings may change things as well.