Skip to content

chore(refactor): optimize memory hygiene by extracting inline Regex instances to constants#263

Merged
ProdigyV21 merged 1 commit into
ProdigyV21:mainfrom
Himanth-reddy:chore/auto-refactor-20260524-18408693841350593791
May 26, 2026
Merged

chore(refactor): optimize memory hygiene by extracting inline Regex instances to constants#263
ProdigyV21 merged 1 commit into
ProdigyV21:mainfrom
Himanth-reddy:chore/auto-refactor-20260524-18408693841350593791

Conversation

@Himanth-reddy
Copy link
Copy Markdown
Collaborator

Summary of Changes

  • app/src/main/kotlin/com/arflix/tv/data/repository/CollectionTemplateManifest.kt: Extracted inline Regex("[^a-z0-9]+") instantiation in slugify to a top-level private object CollectionManifestRegexes.
  • app/src/main/kotlin/com/arflix/tv/data/repository/HttpLocalScraperRuntime.kt: Replaced multiple inline Regex creations with references to existing or newly created companion object constants (EPISODE_DIV_REGEX, DATA_IFRAME_REGEX, PLAYER_IFRAME_REGEX, T_HASH_REGEX, etc.) to avoid recompilation.
  • app/src/main/kotlin/com/arflix/tv/util/ProfileAvatarFiles.kt: Moved inline Regex("[^A-Za-z0-9._-]") into ProfileAvatarRegexes.SANITIZATION_REGEX.
  • app/src/main/kotlin/com/arflix/tv/util/SubtitleScoring.kt: Extracted inline regexes (PURE_NUMBERS_RE, SUBTITLE_BRACKET_RE, SEPARATOR_RE) to file-level private constants.
  • app/src/main/kotlin/com/arflix/tv/util/AppLogger.kt: Extracted Regex("[^A-Za-z0-9_.-]") into AppLoggerRegexes.FILENAME_SANITIZATION_REGEX.
  • app/src/main/kotlin/com/arflix/tv/ui/screens/player/PlayerScreen.kt: Extracted Regex instances into PlayerScreenRegexes top-level private object to avoid triggering recomposition and gc pressure during render paths.

Why this improves the codebase

This explicitly fulfills the checklist directive for Memory Hygiene. By pulling heavy, immutable Regex instances out of hot paths, utility loops, and Compose functions, we drastically mitigate GC churn and avoid unnecessary regex recompilation overhead.

Verification

  • Code compiles successfully inside the sandbox environment.
  • No new features were added; existing features were fortified and optimized across the modified files.
  • Automated tests pass.

@ProdigyV21
Copy link
Copy Markdown
Owner

This one is not ready to merge yet because it conflicts with latest main.

The conflict is in HttpLocalScraperRuntime.kt. Main already has some of the same regex cleanup, but with different constant names like DIV_EP_REGEX, IFRAME_PLAYER_REGEX, and T_HASH_T_REGEX. This PR adds similar ones again as EPISODE_DIV_REGEX, PLAYER_IFRAME_REGEX, and T_HASH_REGEX, so Git cannot merge it automatically.

Please rebase onto latest main and keep the existing regex constants/names from main instead of adding duplicate renamed versions.

The idea itself is fine and low risk: it is just moving repeated Regex(...) calls into reusable constants. After rebase and conflict cleanup, it should be safe.

@Himanth-reddy Himanth-reddy force-pushed the chore/auto-refactor-20260524-18408693841350593791 branch from 511b35f to 0d1f926 Compare May 26, 2026 08:01
@ProdigyV21 ProdigyV21 merged commit 09a4cac into ProdigyV21:main May 26, 2026
1 check passed
@Himanth-reddy Himanth-reddy deleted the chore/auto-refactor-20260524-18408693841350593791 branch June 2, 2026 15:18
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