perf: stop per-cover HttpClient churn (Android) + scroll-arrow reflow (web)
Android: MusicRepository.coverArtUrl/streamUrl built a fresh SubsonicClient per call — each spins up (and never closes) a Ktor HttpClient. That ran for every cover on every recomposition, causing heavy GC/alloc churn (and a leak) that showed up as scroll/tab lag. Reuse the cached ClientHolder client for URL building instead. Web: the home scroll-row arrows called getBoundingClientRect on every scroll event (layout thrashing). Split it: only toggle arrow visibility on scroll (rAF-throttled); do the getBoundingClientRect vertical-centering only on resize/content change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
ef25ac3100
commit
d50e22b62d
2 files changed
+17
-9
No files matched your search
@@ -76,8 +76,9 @@ class MusicRepository(private val context: Context) {
|
||||
}
|
||||
}
|
||||
val creds = lastCredentials ?: return null
|
||||
return SubsonicClient(creds.serverUrl, creds.username, creds.password)
|
||||
.coverArtUrl(id ?: return null, size)
|
||||
// Reuse the cached client — building a fresh SubsonicClient here spins up a whole Ktor
|
||||
// HttpClient per cover (and never closes it), which is heavy GC/alloc churn while scrolling.
|
||||
return ClientHolder.get(creds).coverArtUrl(id ?: return null, size)
|
||||
}
|
||||
|
||||
fun streamUrl(id: String): String? {
|
||||
@@ -86,7 +87,7 @@ class MusicRepository(private val context: Context) {
|
||||
if (f.exists()) return Uri.fromFile(f).toString()
|
||||
}
|
||||
val creds = lastCredentials ?: return null
|
||||
return SubsonicClient(creds.serverUrl, creds.username, creds.password).streamUrl(id)
|
||||
return ClientHolder.get(creds).streamUrl(id) // reuse cached client (no per-call HttpClient)
|
||||
}
|
||||
|
||||
private fun offlineRepo(): OfflineRepository? = runCatching {
|
||||
|
||||
Reference in new issue
Block a user