Skip to content

⚡ Bolt: Optimize Hashtag stream allocations#112

Merged
dlukt merged 2 commits intomasterfrom
bolt/hashtag-stream-optimization-9813122932523157364
Mar 12, 2026
Merged

⚡ Bolt: Optimize Hashtag stream allocations#112
dlukt merged 2 commits intomasterfrom
bolt/hashtag-stream-optimization-9813122932523157364

Conversation

@dlukt
Copy link
Owner

@dlukt dlukt commented Mar 12, 2026

💡 What: Replaced Java Streams (stream().mapToInt().sum()) in HashtagTimelineFragment.updateHeader with simple loop methods (getWeekPosts(), getWeekAccounts()) in the Hashtag model.
🎯 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 HashtagTimelineFragment successfully 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

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>
@google-labs-jules
Copy link

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings March 12, 2026 06:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 use Hashtag#getWeekPosts() / Hashtag#getWeekAccounts() instead of stream().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.

Comment on lines +60 to +67
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;
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@dlukt
Copy link
Owner Author

dlukt commented Mar 12, 2026

@jules
mastodon/src/main/java/de/icod/techidon/model/Hashtag.java
Comment on lines +60 to +67
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;
https://github.com/apps/copilot-pull-request-reviewer AI
4 hours ago

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.

@google-labs-jules
Copy link

@jules
mastodon/src/main/java/de/icod/techidon/model/Hashtag.java
Comment on lines +60 to +67
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;
https://github.com/apps/copilot-pull-request-reviewer AI
4 hours ago

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 getWeekAccounts() handling sum calculation, empty list, and null history.

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>
@dlukt dlukt merged commit a79cc8c into master Mar 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants