Skip to content

feat: add thread cap setting for improved stability and performance on slow storage mediums#570

Closed
ProRapSuperstarOriginalMaster wants to merge 0 commit intoutkarshdalal:masterfrom
ProRapSuperstarOriginalMaster:feature/sd-card-download-cap
Closed

feat: add thread cap setting for improved stability and performance on slow storage mediums#570
ProRapSuperstarOriginalMaster wants to merge 0 commit intoutkarshdalal:masterfrom
ProRapSuperstarOriginalMaster:feature/sd-card-download-cap

Conversation

@ProRapSuperstarOriginalMaster
Copy link

@ProRapSuperstarOriginalMaster ProRapSuperstarOriginalMaster commented Feb 19, 2026

I added a setting to cap the decompression thread to 1, as well as significantly lowering the effect of the download speed setting on download threads. The purpose of this setting is to adapt these to the limitations of simpler storage mediums (primarily micro SD cards), and avoid I/O jams that negatively affects download performance and app stability.

Through my own testing this solves an issue where the app interface would become extremely unstable and crash frequently during downloads. The gains in stability and lowering download performance to the hardware bottleneck seem to counteract any losses to speed. And through my own testing as well as some rudimentary research into the workings of exFAT formatted SD cards I have determined that decompression threads should not exceed 1, and that download threads benefit from being higher than the decompression threads. Likely due to decompression being faster than downloads, and allowing the decompression thread a buffer to always work at full capacity.

I have decided to keep the download threads variable through the speed setting, as I believe the optimal download threads will also depend on network speeds. I have also decided not to lock the setting behind the condition of external storage being used, not force it on for external storage. As I believe there could be internal storage mediums that also benefit from this setting, and external storage mediums that don't.

P.S. This is my first ever commit/pull request to an open source repo, apologies in advance if I've done anything wrong or if my code is bad.


Summary by cubic

Added an optional “SD card cap” setting to optimize downloads on slower storage (e.g., microSD) by capping decompression to 1 thread and reducing download threads. This lowers I/O contention and improves stability during large downloads.

  • New Features
    • New sdCardCap preference and Settings toggle: “Optimize for slower storage mediums by capping threads.”
    • When enabled: decompression = 1 thread; download threads scaled down to 1–4 based on speed (8/16/24/32). When disabled: existing CPU-core ratio logic remains.
    • Not tied to external storage detection, so it can be used for any slow storage.

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

Summary by CodeRabbit

  • New Features
    • Added SD card capacity optimization setting in Downloads preferences to limit download and decompression thread counts, improving performance on slower storage devices. When enabled, threading is capped based on speed settings to prevent resource contention.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 19, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

This change introduces an SD card capacity optimization feature that adds a new boolean preference to control download thread count limits. The setting propagates through the preference manager and conditionally caps thread counts in the download service based on user configuration.

Changes

Cohort / File(s) Summary
Preference Storage
app/src/main/java/app/gamenative/PrefManager.kt
Added new boolean preference key SD_CARD_CAP with public property sdCardCap using getter/setter pattern for persistence.
Download Service Logic
app/src/main/java/app/gamenative/service/SteamService.kt
Introduced conditional branching based on sdCardCap preference; when enabled, applies thread count caps (8/16/24/32 per speed setting) instead of dynamic calculation from CPU cores.
Settings UI
app/src/main/java/app/gamenative/ui/screen/settings/SettingsGroupInterface.kt
Added new settings toggle for SD card capacity optimization in Downloads section with remembered state synchronized to PrefManager.
UI Strings
app/src/main/res/values/strings.xml
Added two string resources: title and subtitle for the SD card capacity settings toggle.

Sequence Diagram

sequenceDiagram
    actor User
    participant Settings as Settings UI
    participant Pref as PrefManager
    participant Service as SteamService
    participant Downloader as DepotDownloader

    User->>Settings: Toggle SD Card Cap
    Settings->>Pref: Update sdCardCap
    Pref->>Pref: Persist preference
    Note over Settings,Pref: Preference saved
    
    rect rgba(100, 150, 200, 0.5)
        Service->>Pref: Read sdCardCap
        alt Cap Enabled
            Pref-->>Service: true
            Service->>Service: Apply thread caps<br/>(8/16/24/32)
        else Cap Disabled
            Pref-->>Service: false
            Service->>Service: Calculate threads<br/>from CPU cores
        end
    end
    
    Service->>Downloader: Initialize with<br/>maxDownloads/maxDecompress
    Downloader-->>Service: Ready to download
Loading

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly Related PRs

  • #425 — Modifies download/decompress thread calculation logic in SteamService with ratio adjustments and cap handling
  • #260 — Adds boolean preference property to PrefManager with getter/setter pattern
  • #328 — Adjusts DepotDownloader initialization and thread count calculations in SteamService

Poem

🐰 A little toggle for the cards so slow,
Thread counts dance, now fast, now low,
Preferences saved with a fluffy hop,
SD storage caps that never stop! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately summarizes the main change: adding a thread cap setting for slow storage mediums, which aligns with the core functionality added across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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 and usage tips.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 4 files

@utkarshdalal
Copy link
Owner

Hi, thanks for this PR. I'll review it soon.

@utkarshdalal
Copy link
Owner

Also the tests are failing?

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