Skip to content

Optimize package icon loading and memory management#5069

Merged
Gabriel Dufresne (GabrielDuf) merged 8 commits into
mainfrom
perf/idle-memory-optimizations
Jul 10, 2026
Merged

Optimize package icon loading and memory management#5069
Gabriel Dufresne (GabrielDuf) merged 8 commits into
mainfrom
perf/idle-memory-optimizations

Conversation

@GabrielDuf

Copy link
Copy Markdown
Contributor

This pull request introduces significant improvements to memory usage and icon loading efficiency in the application. The changes implement a memory trimming mechanism for Windows, overhaul the package icon loading and caching system to be more performant and memory-friendly, and add logic to only load icons for visible rows. Additionally, icons are now downscaled to reduce memory usage, and the icon cache can be reset more reliably. The most important changes are grouped below:

Memory Management Improvements:

  • Added a MemoryTrimmer utility for Windows that returns unused memory to the OS after UI loads settle, reducing the app's working set. This is triggered after loading completes and can be canceled if a new load starts (MemoryTrimmer.cs, MainWindowViewModel.cs, UniGetUI.Avalonia.csproj).
  • Enabled .NET's GC memory conservation mode in the project file to further reduce idle memory usage (UniGetUI.Avalonia.csproj).

Icon Loading and Caching Overhaul:

  • Replaced the old concurrent dictionary icon cache with a custom LRU cache, capped at 512 entries, to reduce memory pressure and avoid rooting unused bitmaps. The cache can now be cleared programmatically (PackageCollections.cs).

  • Increased icon loading concurrency and added per-row cancellation tokens to ensure that icon loads for discarded rows are canceled, preventing memory leaks (PackageCollections.cs).

  • Icons are now loaded lazily only when their row becomes visible, rather than preloading for all results. This is coordinated via a new PackageIconLoader attached property and corresponding XAML changes (PackageIconLoader.cs, AbstractPackagesPage.axaml).
    Icon Decoding and Memory Usage:

  • Added logic to downscale oversized icons to a maximum of 128x128 pixels before caching, reducing memory usage for large icon files (PackageCollections.cs).

  • Improved error handling and cancellation support during icon decoding and loading, making the UI more responsive and robust (PackageCollections.cs).

Other Improvements:

  • Limited the number of results returned by WinGet search to 100 to avoid UI freezes and memory spikes (WinGetCliHelper.cs).

These changes collectively result in a more responsive UI, lower memory footprint, and improved user experience, especially when browsing large package lists or running the app for extended periods.

@GabrielDuf Gabriel Dufresne (GabrielDuf) merged commit 592c541 into main Jul 10, 2026
5 checks passed
@GabrielDuf Gabriel Dufresne (GabrielDuf) deleted the perf/idle-memory-optimizations branch July 10, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants