⚡ Bolt: Optimize Hashtag stream allocations#112
Conversation
This commit replaces the use of Java Streams (`stream().mapToInt().sum()`) in `HashtagTimelineFragment.updateHeader` with explicit loops inside the `Hashtag` model (`getWeekPosts()`, `getWeekAccounts()`). This reduces object allocation and GC overhead during UI rendering. Co-authored-by: dlukt <201112286+dlukt@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.
Pull request overview
This PR reduces UI-thread allocations during hashtag header updates by replacing Java Stream-based summations with loop-based helper methods on the Hashtag model.
Changes:
- Added
Hashtag#getWeekAccounts()to compute weekly participant totals via a simple loop. - Updated
HashtagTimelineFragment.updateHeader()to useHashtag#getWeekPosts()/Hashtag#getWeekAccounts()instead ofstream().mapToInt(...).sum(). - Documented the optimization in
.jules/bolt.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| mastodon/src/main/java/de/icod/techidon/model/Hashtag.java | Adds a loop-based weekly accounts aggregation helper used by UI. |
| mastodon/src/main/java/de/icod/techidon/fragments/HashtagTimelineFragment.java | Switches header computations from Streams to model helpers to reduce allocations. |
| .jules/bolt.md | Records the optimization in the Bolt performance log. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public int getWeekAccounts(){ | ||
| // Optimization: Use loop instead of Stream to avoid allocation overhead in hot paths. | ||
| if(history==null) return 0; | ||
| int sum=0; | ||
| for(History h:history){ | ||
| sum+=h.accounts; | ||
| } | ||
| return sum; |
There was a problem hiding this comment.
getWeekAccounts() introduces new logic that is now used by HashtagTimelineFragment.updateHeader, but there are existing unit tests covering Hashtag.getWeekPosts() (see mastodon/src/test/.../HashtagTest). Please add comparable tests for getWeekAccounts() (sum, empty list, and null history) to prevent regressions.
|
@jules getWeekAccounts() introduces new logic that is now used by HashtagTimelineFragment.updateHeader, but there are existing unit tests covering Hashtag.getWeekPosts() (see mastodon/src/test/.../HashtagTest). Please add comparable tests for getWeekAccounts() (sum, empty list, and null history) to prevent regressions. |
Thanks for the review! I've added comparable unit tests for |
Addresses code review feedback by adding tests to cover the functionality of Hashtag.getWeekAccounts(), verifying proper summation as well as behavior when the history list is empty or null. Co-authored-by: dlukt <201112286+dlukt@users.noreply.github.com>
💡 What: Replaced Java Streams (
stream().mapToInt().sum()) inHashtagTimelineFragment.updateHeaderwith simple loop methods (getWeekPosts(),getWeekAccounts()) in theHashtagmodel.🎯 Why: The original stream operations execute every time the fragment header updates, causing unnecessary object allocations and GC churn on the UI thread.
📊 Impact: Reduces allocation overhead for Stream, Optional, lambda, and Collector objects during UI rendering.
🔬 Measurement: Verify that
HashtagTimelineFragmentsuccessfully loads and updates the post and participant count in the header without throwing errors, and observe a reduction in GC pauses when profiling the rendering hot path.PR created automatically by Jules for task 9813122932523157364 started by @dlukt