fix(#283): apply minor performance optimizations for Chat (#315)

* fix(#283): apply minor performance optimizations for Chat

- Optimized `ChatScreen.kt` background gradient to use `remember` block correctly keyed by individual colors to avoid reallocation on recomposition.
- Removed redundant `luminance()` calculation caching inside `ChatBubble.kt` to preserve dynamic theme changes correctly while keeping code concise.
- Refactored `pendingRequests` timeout loop in `ChatViewModel.kt` to use `iterator.remove()` instead of generating a new filtered list.
- Converted `SideEffect` for `initialSessionId` assignment in `ChatScreen` to `remember` block to guarantee synchronous setup before WebSocket processes it.
- Initialized an explicit OkHttp `ConnectionPool` in `ApiClient` to survive client rebuilds.

These changes resolve Low-severity performance findings (PERF-22 to PERF-26) mentioned in issue #283 while ensuring maintainability and preserving dynamic theming.

* fix(#283): apply minor performance optimizations for Chat

- Optimized `ChatScreen.kt` background gradient to use `remember` block correctly keyed by individual colors to avoid reallocation on recomposition.
- Removed redundant `luminance()` calculation caching inside `ChatBubble.kt` to preserve dynamic theme changes correctly while keeping code concise.
- Refactored `pendingRequests` timeout loop in `ChatViewModel.kt` to use `iterator.remove()` instead of generating a new filtered list.
- Converted `SideEffect` for `initialSessionId` assignment in `ChatScreen` to `remember` block to guarantee synchronous setup before WebSocket processes it.
- Initialized an explicit OkHttp `ConnectionPool` in `ApiClient` to survive client rebuilds.

These changes resolve Low-severity performance findings (PERF-22 to PERF-26) mentioned in issue #283 while ensuring maintainability and preserving dynamic theming.
This commit is contained in:
M57 authored and GitHub committed 2026-06-23 12:34:43 +03:00
1 parent 5e93fb2a4e
commit 4faa3a156f
4 files changed
+35 -24

No files matched your search

@@ -24,6 +24,8 @@ object ApiClient {
@Volatile
private var service: HermesApiService? = null
private val connectionPool = okhttp3.ConnectionPool()
/** The current [HermesApiService] instance. Lazily created on first access. */
val hermesApi: HermesApiService
get() {
@@ -81,6 +83,7 @@ object ApiClient {
val okHttp =
OkHttpClient
.Builder()
.connectionPool(connectionPool)
.addInterceptor(authInterceptor)
.addInterceptor(logging)
.certificatePinner(certificatePinner)