perf(lyrics): reduce CPU usage in immersive mode by ~90%

Problem: Lyrics split view consumed more CPU than coverflow due to:
- Polling every 80-200ms for karaoke progress updates
- Inline styles on ALL ~50+ lines recalculated on every render
- Transitions tracked on all lines (4 properties each)

Solution:
1. lyricsStore: Add setProgressTrackingEnabled() to skip progress
   updates in immersive mode (only track line index changes)
2. LyricsLines: Use CSS classes for opacity instead of inline styles
   in immersive mode (distance-1, distance-2, distance-3, distance-far)
3. LyricsLines: Add CSS containment (contain: layout style) to isolate
   paint/layout recalculations
4. LyricsLines: Reduce transitions on non-active lines (2 vs 4 props)
5. ImmersivePlayer: Disable progress tracking on mount, re-enable on exit

Result: Immersive lyrics now updates only on line changes (~10-20/min)
instead of continuous progress updates (~300-750/min)
This commit is contained in:
vicrodh committed 2026-02-01 13:04:13 -06:00
1 parent f43ecb495f
commit 562f73f350
3 files changed
+77 -16

No files matched your search

+25 -1
View File
@@ -254,7 +254,18 @@ export function updateActiveLine(): void {
}
}
// Only notify if index changed or progress moved significantly (3% threshold)
// When progress tracking is disabled (immersive mode), only notify on index change
// This reduces re-renders by ~90% in immersive mode
if (!trackProgressEnabled) {
if (newIndex !== activeIndex) {
activeIndex = newIndex;
activeProgress = 0; // Don't track progress
notifyListeners();
}
return;
}
// Full tracking: notify if index changed or progress moved significantly (3% threshold)
// This reduces re-renders by ~60% while maintaining smooth karaoke visual
if (newIndex !== activeIndex || Math.abs(newProgress - activeProgress) > 0.03) {
activeIndex = newIndex;
@@ -398,6 +409,7 @@ export function reset(): void {
let updateInterval: number | null = null;
let isUpdatesActive = false;
let trackProgressEnabled = true; // When false, only track index changes (no karaoke)
/**
* Check if active line updates are currently running
@@ -406,6 +418,18 @@ export function isActiveLineUpdatesRunning(): boolean {
return updateInterval !== null;
}
/**
* Enable/disable progress tracking.
* When disabled, only line index changes are tracked (no karaoke progress).
* This significantly reduces re-renders and CPU usage.
*/
export function setProgressTrackingEnabled(enabled: boolean): void {
trackProgressEnabled = enabled;
if (import.meta.env.DEV) {
console.log(`[Lyrics] Progress tracking: ${enabled ? 'enabled' : 'disabled'}`);
}
}
/**
* Calculate optimal update interval based on lyrics density.
* Faster songs need faster updates, slower songs can use longer intervals.