Skip to content

Fix: An attempt to reduce ANRs in the Tab switcher#7774

Merged
0nko merged 9 commits intodevelopfrom
fix/ondrej/tab-switcher-anr
Mar 3, 2026
Merged

Fix: An attempt to reduce ANRs in the Tab switcher#7774
0nko merged 9 commits intodevelopfrom
fix/ondrej/tab-switcher-anr

Conversation

@0nko
Copy link
Copy Markdown
Member

@0nko 0nko commented Feb 19, 2026

Task/Issue URL: https://app.asana.com/1/137249556945/project/1207418217763355/task/1213195941245227?focus=true

Description

This PR adds a couple of optimizations to attempt to reduce ANRs in the Tab switcher:

Steps to test this PR

  • Generate tabs in the Developer settings
  • Go to the tab switcher
  • Smoke test drag & drop
  • Smoke test tab deletion
  • Smoke test fast scrolling

Note

Medium Risk
Changes RecyclerView diffing and async image-loading lifecycle in the tab switcher, which can affect item updates, scrolling behavior, and potential visual inconsistencies if cancellation/state is mishandled.

Overview
Reduces main-thread work in the tab switcher by switching from manual DiffUtil.calculateDiff to AsyncListDiffer with a new DiffUtil.ItemCallback-based TabSwitcherItemDiffCallback (including a dynamic isDragging() alpha payload for the tracker info tile).

Adds per-ViewHolder coroutine job tracking/cancellation and explicit onViewRecycled cleanup to stop favicon/preview loading when items are recycled, and updates favicon loading to allow Glide caching by removing DiskCacheStrategy.NONE/skipMemoryCache(true) in FaviconImageView.

Written by Cursor Bugbot for commit 5f13c2a. This will update automatically on new commits. Configure here.

Comment thread app/src/main/java/com/duckduckgo/app/tabs/ui/TabSwitcherAdapter.kt Outdated
@GerardPaligot GerardPaligot self-assigned this Mar 2, 2026
Copy link
Copy Markdown
Contributor

@GerardPaligot GerardPaligot left a comment

Choose a reason for hiding this comment

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

Nice improvement, I wasn't able to reproduce the crash myself, but I "load-tested" the application and the tab switcher screen to verify your changes under stress. I've also posted a few comments with some minor suggestions and questions.

Comment thread app/src/main/java/com/duckduckgo/app/tabs/ui/TabSwitcherAdapter.kt
Comment thread app/src/main/java/com/duckduckgo/app/tabs/ui/TabSwitcherAdapter.kt
oldItem: TabSwitcherItem,
newItem: TabSwitcherItem,
): Bundle {
): Any {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: I'm pretty sure we can keep Bundle here.

updateData(swapped)
val swapped = pendingList.swap(from, to)
pendingList = swapped
differ.submitList(swapped)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: reuse updateData function to avoid any future error.

updateData(pendingList.swap(from, to))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good suggestion, thanks!

@0nko
Copy link
Copy Markdown
Member Author

0nko commented Mar 2, 2026

Thanks for the review, @GerardPaligot. I've addressed all comments, ready for another round!

cursor[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

@GerardPaligot GerardPaligot left a comment

Choose a reason for hiding this comment

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

LGTM

@0nko 0nko merged commit 48319a2 into develop Mar 3, 2026
12 checks passed
@0nko 0nko deleted the fix/ondrej/tab-switcher-anr branch March 3, 2026 08:27
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.

3 participants