Repository navigation
fix(media): free link preview, site icon and Markdown caches on memory pressure - #237
Merged
Merged
Conversation
…y pressure Ports iOS #309 (ab383d8a). Android already posts a memory warning (MemoryWarningCenter, from onTrimMemory >= RUNNING_LOW and onLowMemory), but only the media reference loader listened. Now these also empty on a warning: - the link preview and site icon loaders' memory tier (CoalescedDiskCache); disk stays, so the next load reads it back without a request - a transcript's LinkPreviewStore: decoded pictures and remembered reply links, which the next draw decodes and extracts again - MarkdownStreamStore and InlineCache; the next text parses from the start Site icons now keep at most 128 in memory (they had no cap), and disk hits keep the 64/128 limits too (they used to write past them). MemoryWarningCenter.observe returns a remover so a closed LinkPreviewStore stops listening. MarkdownStreamStore's eviction-order change isn't ported. Verified: full scripts/check.sh on the Android VM. New tests fail with the observer and the limit turned off: diskHitsStayWithinTheMemoryLimit, aMemoryWarningEmptiesTheLoaderButNotTheDisk, siteIconsKeepAtMost128InMemory, aMemoryWarningEmptiesSiteIconMemory, aMemoryWarningKeepsWhatRowsShow, inlineCacheEmptiesEveryTableOnAMemoryWarning, markdownStreamsGoOnAMemoryWarning.
- CoalescedDiskCache.remember never evicts the entry it just kept, so an offline reopen still shows a stale card once memory is full. - Only the live singletons observe MemoryWarningCenter.default; test instances no longer pile up on the shared center. - InlineCache registers after its tables exist. - LinkPreviewStore keeps at most 256 remembered replies, as iOS does. - Tests: close() stops the purge, the row-keeping test no longer reads the fake loader after the purge, the site-icon warning test reads the disk, the cold-miss test fills memory first, rememberedRepliesAreBounded. - Parity rows and test tables updated. Verified: `vm.sh check :feature:media :feature:transcript` passes; with the eviction fix, the reply cap or the close() unregister reverted, the matching tests fail.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports iOS #309 (ab383d8a). The app's existing
MemoryWarningCenternow empties these caches as well as the media reference loader:LinkPreviewStore: decoded pictures and remembered reply links. The next draw makes them again, so nothing on screen goes blank.MarkdownStreamStoreandInlineCache. A part's next text parses from the start.When it fires:
onTrimMemoryat RUNNING_LOW or above, andonLowMemory. On Android 14+ only UI_HIDDEN and BACKGROUND are delivered, so in practice the purge runs every time the app leaves the screen (Home, switching apps, opening a link in the browser). Android's guidance is to free UI caches there. On the emulator, switching away and back looks the same as on dev: the transcript, cards and icons are drawn in every frame of the return, with no blank, plain card or layout shift (frame by frame, 3–4 runs each onrich-link-arrivalandlong). The cost is a hot return about 40–50 ms slower on the long transcript, while the Markdown parses again.Other changes:
MemoryWarningCenter.observereturns a remover, so a closedLinkPreviewStorestops listening.Not ported: the iOS
MarkdownStreamStoreeviction-order change, the xattr sweep and decode-on-draw. Follow-ups: the drawer'sProjectIconLoadercache, and the:serverparsed-message cache.Nothing visible changes, so no media.
Verified: full
scripts/check.shon the Android VM. The new tests fail with the observers, the limits, the eviction fix or the reply cap turned off. Emulator app-switch comparison against dev as above.