Skip to content

perf: optimize memory usage and cache efficiency for large datasets#318

Open
saidai-bhuvanesh wants to merge 8 commits into
ProdigyV21:mainfrom
saidai-bhuvanesh:main
Open

perf: optimize memory usage and cache efficiency for large datasets#318
saidai-bhuvanesh wants to merge 8 commits into
ProdigyV21:mainfrom
saidai-bhuvanesh:main

Conversation

@saidai-bhuvanesh
Copy link
Copy Markdown
Contributor

Overview

This PR addresses Phase 5: Memory Optimization & Large Dataset Stability Audit.
It introduces critical memory optimizations to reduce allocation pressure, eliminate hidden memory leaks, and optimize cache structures across the IPTV repository, EPG index database, and image loading pipelines. These changes ensure better long-session stability and reduced heap usage, particularly when handling large IPTV playlists (50k+ channels) and dense EPG data on Android TV devices.

Key Changes

  1. IPTV Repository & Playlist Parser:
    • Reduced guideKeyCandidatesCache size from 16384 to 4096 to save heap memory.
    • Prevented memory leaks by properly clearing channel lookups in invalidateCache().
    • Avoided redundant list flattening during aggregate snapshot loading.
    • Prevented empty map allocations and deduplicated EPG map construction.
    • Filtered xmlChannelNameMap against active channels during XMLTV parsing, reducing the map size by ~95%.
  2. EPG Indexing Database:
    • Implemented direct row-by-row writing (insertNowNextRows) into SQLite transactions, completely avoiding the massive temporary list allocation caused by the previous flattening approach.
    • Replaced string formatting deduplication with a lightweight ProgramDedupKey object to prevent StringBuilder allocations.
  3. Image Loading & Coil Optimization:
    • Eliminated custom rememberMetadataLogoImageLoader instances on the Home and Details screens which previously spawned multiple redundant thread pools and memory caches.
    • Standardized on the single application-wide context.imageLoader.
    • Maintained alpha-channel transparency by configuring specific image requests with Bitmap.Config.ARGB_8888 overriding the global RGB_565 optimization.

Verification

  • Clean compilation of playDebugKotlin target.
  • All unit tests pass successfully.
  • Alpha-transparency preserved on metadata logos without regressions.

@ProdigyV21
Copy link
Copy Markdown
Owner

This looks like a useful memory/performance PR, especially for large IPTV playlists and EPG data, but it is not ready to merge yet.

It currently conflicts with latest main in IptvRepository.kt and IptvRepositoryOptimizationTest.kt, likely because main already includes the recent IPTV/EPG refresh work from PR317. Please rebase this PR onto latest main and keep the current main behavior, then reapply only the extra memory optimizations from this PR.

Also please remove trim.py from the PR. It looks like a local cleanup helper script, not project source code.

After that I can re-check compile/tests.

@saidai-bhuvanesh
Copy link
Copy Markdown
Contributor Author

saidai-bhuvanesh commented Jun 5, 2026 via email

@saidai-bhuvanesh
Copy link
Copy Markdown
Contributor Author

saidai-bhuvanesh commented Jun 5, 2026 via email

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