Skip to content

Offload HTML parsing from RecyclerView bind to background + caching to reduce UI jank#5

Merged
dimonvideo merged 2 commits into
masterfrom
codex/optimize-html-render-for-lists
Apr 7, 2026
Merged

Offload HTML parsing from RecyclerView bind to background + caching to reduce UI jank#5
dimonvideo merged 2 commits into
masterfrom
codex/optimize-html-render-for-lists

Conversation

@dimonvideo

Copy link
Copy Markdown
Owner

Motivation

  • Reduce UI jank caused by synchronous Html.fromHtml(...) calls in onBindViewHolder on heavy lists by moving expensive work off the main thread and reusing parsed results.
  • Provide deduplication of in-flight parsing and better lifecycle cleanup to avoid long‑living tasks and memory churn in list adapters.
  • Capture the implementation plan and iteration status in PERFORMANCE_AUDIT.md for future optimizations and rollout tracking.

Description

  • Added in-memory caches (LruCache<String, Spanned>) to AdapterComments, AdapterForumPosts, and AdapterMainRazdel and introduced cache-key builders that include id, text.hashCode() and font size via buildHtmlCacheKey(...) or similar helper.
  • Offloaded HTML parsing to background executors: ExecutorService htmlExecutor in AdapterComments/AdapterForumPosts and existing executor in AdapterMainRazdel, and use a Handler(Looper.getMainLooper()) to safely post parsed Spanned results back to the UI thread while validating TextView tags to avoid stale binds.
  • Implemented deduplication of parsing in AdapterMainRazdel using inFlightHtmlKeys to avoid duplicate background tasks for the same HTML, and enabled setHasStableIds(true) and stable getItemId(...) to reduce unnecessary rebinding.
  • Added proper cleanup: caches are cleared and executors shut down or in-flight keys cleared in onDetachedFromRecyclerView(...) and cleanup() where applicable, and updated PERFORMANCE_AUDIT.md with iteration plan and status notes.

Testing

  • Ran a full project build with ./gradlew assembleDebug which completed successfully.
  • Executed unit tests with ./gradlew test and they passed without failures.
  • Ran ./gradlew lint (static checks) and addressed no blocking issues; lint completed successfully.

Codex Task

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@dimonvideo
dimonvideo merged commit 3682223 into master Apr 7, 2026
0 of 2 checks passed
@dimonvideo
dimonvideo deleted the codex/optimize-html-render-for-lists branch April 7, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant