Skip to content

chore(refactor): optimize memory footprint by extracting inline regex and hardening error handling#291

Merged
ProdigyV21 merged 10 commits into
ProdigyV21:mainfrom
Himanth-reddy:combined-auto-refactors
Jun 3, 2026
Merged

chore(refactor): optimize memory footprint by extracting inline regex and hardening error handling#291
ProdigyV21 merged 10 commits into
ProdigyV21:mainfrom
Himanth-reddy:combined-auto-refactors

Conversation

@Himanth-reddy
Copy link
Copy Markdown
Collaborator

Overview

This PR combines 5 separate auto-refactoring branches into a single, cohesive update to improve application performance and stability. The primary focus of these changes is to reduce memory allocations and CPU overhead during heavily repeated operations, particularly in string parsing and JSON deserialization.

Key Optimizations

  1. Regex Instantiation Optimization:

    • Extracted numerous inline Regex(...) instantiations into static private object or companion object constants (e.g., TvVMRegexes, LiveTvScreenRegexes, etc.).
    • Impact: Prevents the JVM from repeatedly compiling regex state machines on every function invocation (often inside tight loops or UI recompositions). This drastically reduces CPU churn and garbage collection (GC) overhead on memory-constrained TV devices.
  2. Hardened Error Handling:

    • Added explicit AppLogger.e(...) calls to catch blocks that were previously failing silently (such as Hero logo fetch failed, warmXtreamVodCachesIfPossible failed).
    • Impact: Improves telemetry and debugging capabilities without risking application crashes.
  3. Safer Gson TypeToken Usage:

    • Migrated anonymous TypeToken subclass initializations (e.g., object : TypeToken<List<...>>() {}.type) to using TypeToken.getParameterized(...).
    • Impact: Removes the risk of memory leaks caused by implicit outer-class references in anonymous subclasses and reduces runtime reflection costs.

Himanth-reddy and others added 10 commits May 26, 2026 13:25
…andling

- Moved heavily used Regex constants out of functions into companion object in IptvRepository
- Refactored xmlAttribute parsing to use optimized string matching instead of dynamic regex in HomeServerRepository
- Modernized try-catch into runCatching in StreamRepository
- Wrapped volatile Cloud Sync Auth checks in runCatching to avoid flow crashes
…4643912029838459' into combined-auto-refactors

# Conflicts:
#	app/src/main/kotlin/com/arflix/tv/data/repository/IptvRepository.kt
…11037709982985020' into combined-auto-refactors

# Conflicts:
#	app/src/main/kotlin/com/arflix/tv/data/repository/HomeServerRepository.kt
#	app/src/main/kotlin/com/arflix/tv/data/repository/IptvRepository.kt
…28732041108766665' into combined-auto-refactors

# Conflicts:
#	app/src/main/kotlin/com/arflix/tv/ui/screens/tv/TvViewModel.kt
…08693841350593791' into combined-auto-refactors

# Conflicts:
#	app/src/main/kotlin/com/arflix/tv/ui/screens/player/PlayerScreen.kt
@ProdigyV21 ProdigyV21 merged commit 2982a0a into ProdigyV21:main Jun 3, 2026
1 check 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