Skip to content

fix: reduce GC pressure on Search tab for low-end devices - #1202

Open
sang765 wants to merge 2 commits into
rukamori:devfrom
sang765:fix/search-tab-gc-crash
Open

fix: reduce GC pressure on Search tab for low-end devices#1202
sang765 wants to merge 2 commits into
rukamori:devfrom
sang765:fix/search-tab-gc-crash

Conversation

@sang765

@sang765 sang765 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Problem

Crash on low-end device (Android 8.1, MT6580, ~512MB RAM) when navigating to the Search tab:

java.util.concurrent.TimeoutException: com.android.internal.os.BinderInternal$GcWatcher.finalize() timed out after 10 seconds

Root Cause

SearchDiscoveryRepository.loadDiscovery() fires ~17 concurrent network calls simultaneously:

  • 5 top-level requests (explore, charts, albums search, suggested songs, suggested artists)
  • Up to 6 parallel YouTube.next() calls for suggested songs
  • Up to 6 parallel YouTube.artist() calls for suggested artists

Each response creates large object graphs (SongItem, AlbumItem, ArtistItem). On a 512MB device, this burst of allocations overwhelms the GC.

Fix

  1. Batch concurrencyloadSuggestedSongs() and loadSuggestedArtists() now process seed items in batches of 3 (chunked(ConcurrentRequestBatchSize)) instead of all 6 at once
  2. GC yield pointsyield() between batches gives GC a checkpoint to reclaim memory
  3. Reduced seed countMaxSuggestionSeedItems lowered from 6 to 4 (fewer total calls, negligible quality difference since results are capped at 12)

Before: ~17 concurrent network calls at peak
After: Max ~8 concurrent at any moment, with GC yield between batches

Testing

Verified on low-end device (MT6580, 512MB RAM, Android 8.1) — Search tab no longer crashes.

Batch concurrent network requests in loadSuggestedSongs() and
loadSuggestedArtists() to prevent GcWatcher.finalize() timeout
crashes on low-RAM devices (e.g. 512MB MT6580).

- Process seed items in batches of 3 instead of all at once
- Add yield() between batches to let GC breathe
- Lower MaxSuggestionSeedItems from 6 to 4
@sang765

sang765 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Is tested on low-end emulator. This is smaller patch but need to fix

@sang765
sang765 marked this pull request as ready for review August 21, 2026 01:21
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