Skip to content

⚡ Bolt: Optimize event handlers by removing Java Streams#111

Merged
dlukt merged 5 commits intomasterfrom
bolt-optimize-remove-account-posts-event-16029898155976106689
Mar 11, 2026
Merged

⚡ Bolt: Optimize event handlers by removing Java Streams#111
dlukt merged 5 commits intomasterfrom
bolt-optimize-remove-account-posts-event-16029898155976106689

Conversation

@dlukt
Copy link
Owner

@dlukt dlukt commented Mar 11, 2026

💡 What: Replaced Stream.concat().filter().collect() with standard for loops when handling RemoveAccountPostsEvent in both StatusListFragment and NotificationsListFragment.

🎯 Why: The application of Java Streams in these methods creates unnecessary object allocations (Stream instances, Optionals, lambda closures, and Collectors) on the UI thread when processing RemoveAccountPostsEvent (e.g. from blocking or muting an account). In an Android environment, particularly within lists/fragments, these allocations contribute to garbage collection churn. While this event may not be as high-frequency as onBindViewHolder, eliminating Stream allocations follows the established architectural pattern to reduce memory pressure.

📊 Impact: Eliminates Stream overhead during post removal processing. Prevents potential GC-related jank associated with temporary object allocations.

🔬 Measurement: Verify that un-following, muting, or blocking a user properly removes their posts from the home timeline and notifications view without throwing any ConcurrentModificationExceptions. The behavior should be identical to the pre-optimized state but without the hidden Stream allocations.


PR created automatically by Jules for task 16029898155976106689 started by @dlukt

Replaces the use of `Stream.concat(...).filter(...).collect(...)` in `StatusListFragment.onRemoveAccountPostsEvent` and `NotificationsListFragment.onRemoveAccountPostsEvent` with standard `for` loops and `ArrayList`.

This optimization avoids the overhead of Stream object creation and lambda capturing during UI event handling, reducing GC pressure and adhering to the project's strategy of minimizing Stream allocations in hot paths.

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 11, 2026 06:35
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 aims to reduce UI-thread allocations by replacing Java Stream pipelines with explicit loops when handling RemoveAccountPostsEvent in timeline and notifications fragments.

Changes:

  • Replaced Stream.concat(...).filter(...).collect(...) with for loops in StatusListFragment#onRemoveAccountPostsEvent.
  • Replaced Stream.concat(...).filter(...).collect(...) with for loops in NotificationsListFragment#onRemoveAccountPostsEvent.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
mastodon/src/main/java/de/icod/techidon/fragments/StatusListFragment.java Removes Stream-based filtering/collection during account-post removal handling.
mastodon/src/main/java/de/icod/techidon/fragments/NotificationsListFragment.java Removes Stream-based filtering/collection during account-post removal handling for notifications.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +369 to +372
// Optimization: Use loops instead of Streams to avoid allocation overhead during event handling.
List<Notification> toRemove = new ArrayList<>();
for (Notification n : data) {
if (n.account != null && n.account.id.equals(ev.postsByAccountID)) {
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

Stream/Collectors were removed from this method, and there are no remaining usages in this file, but the imports still exist. Java treats unused imports as compilation errors—please delete the java.util.stream.Stream and java.util.stream.Collectors imports (and any related unused stream imports).

Copilot uses AI. Check for mistakes.
Comment on lines +197 to +200
// Optimization: Use loops instead of Streams to avoid allocation overhead during event handling.
List<Status> toRemove = new ArrayList<>();
for (Status s : data) {
if (s.account.id.equals(ev.postsByAccountID) || (!ev.isUnfollow && s.reblog!=null && s.reblog.account.id.equals(ev.postsByAccountID))) {
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

Stream/Collectors were removed from this method, and there are no remaining usages in this file, but the imports still exist. Java treats unused imports as compilation errors—please delete the java.util.stream.Stream and java.util.stream.Collectors imports (and any related unused stream imports).

Copilot uses AI. Check for mistakes.
dlukt and others added 4 commits March 11, 2026 09:33
…agment.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…agment.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…sListFragment.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…sListFragment.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@dlukt
Copy link
Owner Author

dlukt commented Mar 11, 2026

@jules
Stream/Collectors were removed from 2 files, and there are no remaining usages in this file, but the imports still exist. Java treats unused imports as compilation errors—please delete the java.util.stream.Stream and java.util.stream.Collectors imports (and any related unused stream imports).

mastodon/src/main/java/de/icod/techidon/fragments/StatusListFragment.java
mastodon/src/main/java/de/icod/techidon/fragments/NotificationsListFragment.java

@google-labs-jules
Copy link

@jules
Stream/Collectors were removed from 2 files, and there are no remaining usages in this file, but the imports still exist. Java treats unused imports as compilation errors—please delete the java.util.stream.Stream and java.util.stream.Collectors imports (and any related unused stream imports).

mastodon/src/main/java/de/icod/techidon/fragments/StatusListFragment.java
mastodon/src/main/java/de/icod/techidon/fragments/NotificationsListFragment.java

Thank you for pointing that out! I've removed the unused Stream and Collectors imports from both StatusListFragment.java and NotificationsListFragment.java to prevent compilation errors.

@dlukt dlukt merged commit a5ded25 into master Mar 11, 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