Skip to content

Fix GROUPED dedup frame skipping: run deduplication off main thread - #180

Open
disclosurez wants to merge 1 commit into
Davidona:masterfrom
disclosurez:fix/grouped-dedup-background
Open

Fix GROUPED dedup frame skipping: run deduplication off main thread#180
disclosurez wants to merge 1 commit into
Davidona:masterfrom
disclosurez:fix/grouped-dedup-background

Conversation

@disclosurez

Copy link
Copy Markdown
Contributor

Problem

Enabling GROUPED (or SMART) VOD duplicate handling mode on older Fire TV devices (API 25) causes continuous 50+ frame drops during playback. The buildPresentedMovies() / buildPresentedSeries() functions run groupBy, flatMap, and regex-based title normalization on every browse data emission — but these ran on the main thread via the Flow combine callback, blocking the UI thread and causing Choreographer frame skips.

Additionally, normalizedMovieTitle() calls Normalizer.normalize() (a slow ICU4C JNI call) for every movie title on every emission, even for pure-ASCII IPTV titles where normalization is a no-op.

Fix

  1. Moved deduplication to background dispatcher — Added .flowOn(Dispatchers.Default) to all combine(moviePresentationSettingsFlow) and combine(seriesPresentationSettingsFlow) calls in both MovieRepositoryImpl and SeriesRepositoryImpl. The combine callbacks (which call buildPresentedMovies/buildPresentedSeries) now execute on the Default dispatcher instead of the UI thread.

  2. ASCII fast path in normalizedMovieTitle — Added a NON_ASCII_REGEX check before the Normalizer.normalize() call. For pure-ASCII strings (the vast majority of IPTV movie titles), the ICU4C JNI call is skipped entirely.

  3. Caching — Added ConcurrentHashMap caches for movieDisplayYear() and normalizedMovieTitle() results, keyed by input. Repeated calls with the same movie name (e.g. during screen rotations or re-browses) return instantly without recomputation.

Files changed

  • data/.../repository/MovieRepositoryImpl.kt — flowOn on 8 combine sites
  • data/.../repository/SeriesRepositoryImpl.kt — flowOn on 8 combine sites
  • data/.../util/VodMovieDeduplication.kt — caching + ASCII fast path

- Moved buildPresentedMovies/buildPresentedSeries off the main thread
  via .flowOn(Dispatchers.Default) on all combine calls with
  moviePresentationSettingsFlow / seriesPresentationSettingsFlow.
- Added ASCII fast path in normalizedMovieTitle to avoid slow
  Normalizer.normalize() JNI call on API 25 for pure-ASCII titles.
- Added ConcurrentHashMap caches for movieDisplayYear and
  normalizedMovieTitle results to avoid repeated regex evaluation.
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.

1 participant