⚡ Bolt: Optimize historyMaxMin in AdvancedComponents.kt - #203
⚡ Bolt: Optimize historyMaxMin in AdvancedComponents.kt#203alvin000009238 wants to merge 1 commit into
Conversation
…omponents.kt Co-authored-by: alvin000009238 <107313913+alvin000009238@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Code Review
This pull request optimizes nested list allocations inside a Jetpack Compose remember block in AdvancedComponents.kt by replacing nested collection operations with a single-pass loop and tracking min/max values manually, which is also documented in .jules/bolt.md. The reviewer suggested further optimization to reduce object churn by hoisting the foundKeys set allocation outside the loop and clearing it on each iteration, as well as removing a redundant null check.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| val minMap = mutableMapOf<String, Double>() | ||
| val maxMap = mutableMapOf<String, Double>() | ||
|
|
||
| allHistory.forEach { r -> | ||
| val foundKeys = mutableSetOf<String>() | ||
| r.subjects.forEach { historySubject -> | ||
| val key = cleanSubjectName(historySubject.subjectName) | ||
| if (key in reportKeys && foundKeys.add(key)) { | ||
| val score = historySubject.scoreValue | ||
| if (score != null) { | ||
| val currentMin = minMap[key] | ||
| if (currentMin == null || score < currentMin) { | ||
| minMap[key] = score | ||
| } | ||
| val currentMax = maxMap[key] | ||
| if (currentMax == null || score > currentMax) { | ||
| maxMap[key] = score | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
While this PR successfully optimizes nested list allocations, allocating a new foundKeys set (mutableSetOf<String>()) inside the allHistory.forEach loop on every iteration still introduces unnecessary object churn.
We can optimize this further by declaring a single foundKeys set outside the loop and calling clear() on it at the start of each iteration. Additionally, since historySubject.scoreValue returns a non-nullable Double, the score != null check is redundant and can be safely removed.
val minMap = mutableMapOf<String, Double>()
val maxMap = mutableMapOf<String, Double>()
val foundKeys = mutableSetOf<String>()
allHistory.forEach { r ->
foundKeys.clear()
r.subjects.forEach { historySubject ->
val key = cleanSubjectName(historySubject.subjectName)
if (key in reportKeys && foundKeys.add(key)) {
val score = historySubject.scoreValue
val currentMin = minMap[key]
if (currentMin == null || score < currentMin) {
minMap[key] = score
}
val currentMax = maxMap[key]
if (currentMax == null || score > currentMax) {
maxMap[key] = score
}
}
}
}
💡 What:
Optimized the
historyMaxMincalculation inAdvancedComponents.ktby replacing nestedmapNotNulllist allocations with a single-pass loop over theallHistorycollection. The data is accumulated into localminMapandmaxMapcollections.🎯 Why:
The previous code used
report.subjects.forEachand nested aallHistory.mapNotNullinside it, which created new lists for every subject during recomposition. This caused significant object churn and memory pressure when the number of subjects and history size increased.📊 Impact:
Reduces memory allocation overhead during recomposition, resulting in a smoother UI experience.
🔬 Measurement:
Created a local benchmark suite testing a mocked list of 50
Reportobjects containing 15Subjectelements, matching 10 report subjects.PR created automatically by Jules for task 16494909569954314235 started by @alvin000009238