Skip to content

🐛 fix Coil memory cache limit being overridden to 435 MiB - #4912

Merged
guiyanakuang merged 1 commit into
mainfrom
zap/idle-memory-footprint
Sep 3, 2026
Merged

🐛 fix Coil memory cache limit being overridden to 435 MiB#4912
guiyanakuang merged 1 commit into
mainfrom
zap/idle-memory-footprint

Conversation

@guiyanakuang

@guiyanakuang guiyanakuang commented Sep 3, 2026

Copy link
Copy Markdown
Member

Summary

Part of #4908 (903 MB physical footprint after ~6 days idle). Independent of #4911, which handles the thread count side.

DesktopAppModule built the shared Coil MemoryCache with .maxSizeBytes(256 MiB) followed by .maxSizePercent(context, 0.85). In Coil 3 the second call replaces the first (maxSizeBytesFactory is a single field), and on non-Android targets totalAvailableMemoryBytes() is hard-coded to 512 MiB, so the strong-reference LRU was actually 435 MiB. It fills slowly with every thumbnail and preview the user scrolls past, which matches the "grows with uptime, then plateaus" shape in the report. The overriding call is removed so the intended 256 MiB limit applies.

GC tuning flags were part of the first revision of this PR and have been dropped: -XX:ParallelGCThreads is a fixed count rather than a cap and -XX:+UseG1GC would force G1 onto single-core machines that default to Serial, and the remaining periodic-GC / heap-free-ratio flags need real-machine RSS, pause and CPU measurements before they are worth shipping. They will come back as a separate PR once that A/B exists.

Test plan

  • app:compileKotlinDesktop
  • Real-machine: scroll a long image-heavy history to confirm previews still stay cached and responsive

The Coil MemoryCache builder called maxSizeBytes(256 MiB) and then
maxSizePercent(0.85), and the second call replaces the first. On
non-Android targets Coil hard-codes the "total memory" at 512 MiB, so the
strong-reference LRU was actually 435 MiB and filled up over days of use,
which is most of the growth reported in #4908. Drop the overriding call so
the intended 256 MiB limit applies.
@guiyanakuang
guiyanakuang force-pushed the zap/idle-memory-footprint branch from eb19cfa to 1307758 Compare September 3, 2026 04:03
@guiyanakuang guiyanakuang changed the title ⚡ cap idle memory footprint with Coil cache fix and G1 tuning 🐛 fix Coil memory cache limit being overridden to 435 MiB Sep 3, 2026
@guiyanakuang
guiyanakuang merged commit f6f12ab into main Sep 3, 2026
6 checks passed
@guiyanakuang
guiyanakuang deleted the zap/idle-memory-footprint branch September 3, 2026 04:05
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