Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
## 2024-07-29 - Kotlin Collection Processing Eagerness
**Learning:** In Kotlin, collection operations like `distinctBy` followed by `take` evaluate eagerly. When applied to large collections (like thousands of local tracks), `distinctBy` will process the entire list and create intermediate collections before `take` is applied.
**Action:** Use `.asSequence()` before chaining operations like `distinctBy` and `take`, and terminate with `.toList()`. This evaluates operations lazily, meaning `take(5)` will stop processing after finding 5 distinct items, completely avoiding processing the rest of the list.
## 2024-05-19 - Replacing pre-sized ArrayList + for loop with List(size) constructor
**Learning:** In Kotlin, creating a `List` using the functional constructor `List(size) { index -> ... }` can be slightly faster and is definitely cleaner than manually sizing an `ArrayList` and using a `for` loop to `.add()` items, even when the `ArrayList` is pre-sized.
**Action:** Default to the `List(size) { ... }` constructor when mapping indexed access (like from an Android framework class or external API that doesn't provide an Iterator) into a Kotlin List.
## 2024-08-02 - Debouncing and offloading state derivation in Jetpack Compose
**Learning:** In Jetpack Compose, computing expensive operations (like filtering large lists based on user input) directly within a synchronous `remember` block blocks the main UI thread. When this happens on every keystroke in a `TextField`, it causes significant UI stutter and input lag.
**Action:** To prevent UI stutter during expensive state derivation, debounce the input using `LaunchedEffect` with `delay` and offload the computation to a background thread using `withContext(Dispatchers.Default)`. This keeps the main thread responsive for typing and animations.
## 2023-10-24 - Optimization: Extract repeated IPC calls
**Learning:** `mediaRouter.routeCount` acts as a getter which can sometimes trigger repeated IPC boundary calls or expensive lookups when used as the upper bound of a loop. (Even if Kotlin's `until` handles evaluation once implicitly, explicit extraction aligns with performance-first readability and specific user demands.)
**Action:** Always extract loop bounds and repetitive IPC-like getters into a local variable before loop evaluation.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class SystemAudioRouteController @Inject constructor(
val mediaRouter = router ?: return emptyList()
val selected = mediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_AUDIO)
val currentRoutes = buildList {
for (routerIndex in 0 until mediaRouter.routeCount) {
val routeCount = mediaRouter.routeCount
for (routerIndex in 0 until routeCount) {
val route = mediaRouter.getRouteAt(routerIndex)
if (route.supportedTypes and MediaRouter.ROUTE_TYPE_LIVE_AUDIO != 0) add(route)
}
Expand Down Expand Up @@ -55,7 +56,8 @@ class SystemAudioRouteController @Inject constructor(
val mediaRouter = router ?: error("Audio output routing is unavailable on this device")
val route = routesById[index]
?: error("The selected audio route is no longer available")
val isStillAvailable = (0 until mediaRouter.routeCount)
val routeCount = mediaRouter.routeCount
val isStillAvailable = (0 until routeCount)
.any { routerIndex -> mediaRouter.getRouteAt(routerIndex) === route }
require(isStillAvailable) { "The selected audio route is no longer available" }
require(route.isEnabled) { "The selected audio route is disabled" }
Expand Down
Loading