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
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
## 2024-05-24 - O(N) Iteration in Cache Size Calculation
**Learning:** Calculating dynamic capacity dynamically via `store.values.sumOf { it.sizeBytes }` effectively incurs an O(N) cost on every `put` because it runs when `trimToCapacity()` calls `dynamicCapacity`. When cache sizes get large, this causes O(NΒ²) overall insertion performance and UI stutters.
**Action:** Use an `AtomicLong` (O(1)) to track the running sum of cache size instead of dynamically iterating through the entire collection.
## 2023-10-05 - [Compose LazyList Performance]
**Learning:** Using `indexOf(item)` inside Compose `items()` loops in a `LazyVerticalGrid` or `LazyColumn` causes unnecessary O(N) operations during recomposition, which leads to dropped frames and laggy scrolling, especially for large lists.
**Action:** Always use `itemsIndexed()` when the index is needed inside the `item` block to provide an O(1) index lookup and ensure smooth scrolling performance.
10 changes: 6 additions & 4 deletions app/src/main/java/com/example/reddittube/ui/main/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,13 @@ private fun BrowseGrid(
horizontalArrangement = Arrangement.spacedBy(10.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)
) {
items(
// ⚑ Bolt: Performance optimization
// Impact: Prevents O(N) lookup (indexOf) for every visible item during composition by using itemsIndexed.
// Measurement: Scrolling through large feed lists will be noticeably smoother with fewer dropped frames.
itemsIndexed(
items = distinctData,
key = { post -> post.id }
) { post ->
val index = distinctData.indexOf(post).coerceAtLeast(0)
key = { _, post -> post.id }
) { index, post ->
VideoCard(
post = post,
isLiked = likedIds.contains(post.id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

Expand Down
Loading