Skip to content

feat(): LibraryViewModel performance improvements#1693

Open
phobos665 wants to merge 3 commits into
utkarshdalal:masterfrom
phobos665:feat/viewmodel-improvements
Open

feat(): LibraryViewModel performance improvements#1693
phobos665 wants to merge 3 commits into
utkarshdalal:masterfrom
phobos665:feat/viewmodel-improvements

Conversation

@phobos665

@phobos665 phobos665 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description

  • Reduce sorting cpu time & memory usage (Cpu is now O(n) instead of O (n log n) e.g. exponential complexity for sorting) - Did this by creating a sortName on entry creation, rather than manipulating both the comparitor and the name on comparison.
  • Created a Job & cache for fetching results so that we can cancel and check the cache before we fetch again. This way we don't have issues with multiple processes trying to receive the results and causing excessive redraws on the UI.

Overall, the UI should be vastly more responsive on initial and further retrievals for games going forward. This also means Carousel should be much more usable.

Recording

Type of Change

  • Bug fix
  • Performance / stability improvement
  • Compatibility improvements
  • Other (requires prior approval)

Checklist

  • If I have access to #code-changes, I have discussed this change there and it has been green-lighted. If I do not have access, I have still provided clear context in this PR. If I skip both, I accept that this change may face delays in review, may not be reviewed at all, or may be closed.
  • This change aligns with the current project scope (core functionality, stability, or performance). If not, it has been explicitly approved beforehand.
  • I have attached a recording of the change.
  • I have read and agree to the contribution guidelines in CONTRIBUTING.md.

Summary by cubic

Speeds up LibraryViewModel filtering, sorting, and pagination to reduce CPU work and UI redraws. The library and carousel feel more responsive on first load and when paging; pagination now cancels stale work.

  • Performance
    • Cache filtered results and slice pages via applyPagination, avoiding re-filter/re-sort on page changes.
    • Add pageJob and filterJob to cancel stale work; guard commits with ensureActive() to prevent outdated UI updates.
    • Precompute sortName per entry for cheaper sorting.
    • Cache Steam size per app/branch in ConcurrentHashMap.
    • Batch installed-branch lookup via SteamService.getAllInstalledApps().
    • Check GOG/Epic/Amazon credentials once per run.
    • Clear caches on refresh and when the Steam app list changes.

Written for commit 0761185. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Performance
    • Improved library filtering and pagination speed by reusing cached filtered+sorted results and re-applying pagination-specific adjustments without re-running the full pipeline.
    • Faster refreshes and page transitions, with improved responsiveness by canceling superseded filtering work.
  • Bug Fixes
    • Improved correctness and consistency of Steam-related filtering and size estimates.
    • More reliable source availability indicators (including badge counts) by evaluating credential checks once per filtering run.

…wercased on creation rather than doing multiple operations. (Go from O(n log n) to O(n). Much nicer.
@phobos665 phobos665 requested a review from utkarshdalal as a code owner July 10, 2026 11:44
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

LibraryViewModel now cancels superseded filtering jobs, caches filtered results for pagination, memoizes Steam size calculations, precomputes sorting and credential data, and centralizes recommendation insertion.

Changes

Library filtering pipeline

Layer / File(s) Summary
Filter cancellation and cached pagination
app/src/main/java/app/gamenative/ui/model/LibraryViewModel.kt
Filtering jobs are synchronized and cancellable, while pagination reuses the cached filtered list and applies recommendation insertion through applyPagination.
Steam filtering and size memoization
app/src/main/java/app/gamenative/ui/model/LibraryViewModel.kt
Steam processing precomputes installed branches and lowercase sort names, memoizes size calculations, and clears the size cache when Steam data or refresh state changes.
Credential-gated source inclusion
app/src/main/java/app/gamenative/ui/model/LibraryViewModel.kt
GOG, Epic, and Amazon credential checks are evaluated once per run and reused for source inclusion and badge counts; cancellation checks are added around sorting and state updates.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant FilterRequest
  participant LibraryViewModel
  participant PaginationState
  FilterRequest->>LibraryViewModel: start filtering
  LibraryViewModel->>LibraryViewModel: cancel prior filter and page jobs
  LibraryViewModel->>PaginationState: cache full filtered list
  FilterRequest->>LibraryViewModel: change page
  LibraryViewModel->>PaginationState: slice cached list and apply pagination
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes the main change: LibraryViewModel performance improvements.
Description check ✅ Passed The PR follows the template and covers the change, type, and checklist; only the recording attachment appears missing.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 1 file

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread app/src/main/java/app/gamenative/ui/model/LibraryViewModel.kt Outdated
…currently runnin jobs to avoid excessive retirevals.
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