Repository navigation
perf: bound image pixel caches, scale thumbnails, and unload closed/background sessions - #1352
Merged
Merged
Conversation
…ackground sessions
Hona
marked this pull request as ready for review
November 26, 2026 21:20
…ve byte eviction, MemorySweep idle state, opening hold)
…n, fix raw_buf shrink, portrait md width, and RAII worker guard
…scroll, sniff SVG/APNG, live weights, fix worker wakeup race)
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.
Why
Live profiling of
opencode-desktop.exe(stroberec_198110, 1,781 MB commit / 1,517 MB private working set) showed 1,165 MB (65.4%) held by 347 live decodedrune_image::MipCPU buffers (including 92×1366×1278screenshots = 805 MB) because:ImageCache::load, 5.33 B/px steady, 9.33–12.33 B/px peak).MediaStore,MdStore, and pluginImageshad no decoded pixel or encoded byte LRU caps.MediaStore::rest()kept every image pinned while its tab stayed open,rest_pixels()requiredtabs.is_empty(), parked server halves were never rested, and active animations (e.g.Thinkingspinner) blockedApp::on_restindefinitely.ImageCaches, re-serialized full JSON pages withserde_json::to_vecsolely to measure byte length, and parked with cross-threadmimallocfrees uncollected.Changes
Image Decoding, Scaling & Peak RAM
crates/session-view/src/images/cache.rs,mod.rs,viewer.rs,composer/attachments.rs,timeline/attachments.rs): Decode composer chips (160 pt), user thumbs (264 pt), gallery tiles (480 pt), markdown images (720 pt), and favicons (32 pt) withrune::ImageCache::load_scaled(keeping animations for small GIF/WebP/APNG within target px). LightboxViewinguses an explicitResolutionstate machine (Decoding { full, fallback } -> Ready) to decode full resolution on demand and release it immediately on close or tab switch.crates/session-view/src/images/cache.rs,mod.rs,markdown.rs): CapMediaStoredecoded pixels at 48 MiB active / 12 MiB rest andmedia:encoded bytes at 24 MiB; capMdStoreat 32 MiB active / 8 MiB rest and 24 MiB encoded bytes. UnifyMediafetcher andRefSlotinto explicit state machines.crates/session-view/src/images/markdown.rs,menu.rs,crates/opencode-plugin-runtime/src/images/,crates/project-icon/): Cap concurrent markdown and plugin image fetch/decode workers to 4 (replacing unboundedtask::spawn), hash plugindata:URL keys, bound plugin source images on rest, enforceimage::Limitson copy-to-PNG and server project icons, and pre-downsample large project icons before converting to 16 B/pxf32RGBA.ImageCache& zero-copy page/file pipelines (apps/desktop/src/session/pages/mod.rs,worker.rs,boot.rs,features/files/src/poll.rs): ShareMediaStore::image_cache()acrosssession-open,session-prefetch, and the timeline; remove the temporaryserde_json::to_vec(value)serialization inpages::read, dropvaluebeforeprepare_images, and moveBody::Imagebytes without cloning.Session Unloading, Lifecycle & Allocator
apps/desktop/src/shell/memory_reclaim.rs,tabs/actions.rs,session/meta/open.rs,tick.rs,kernel.rs): Unload closed sessions immediately onclose_tab, trim background pixels on tab switch, and run an explicitMemorySweepstate machine every 30 s (returning without dirtying cleanTrackedcells or disruptingon_rest) so active spinners never starve reclamation.apps/desktop/src/shell/memory_reclaim.rs,servers/runtime.rs,windows/mod.rs,windows/peer.rs,plugin_host/mod.rs,features/files/src/lib.rs,shell/panels.rs): Rest both active and parked server halves using per-server tab visibility, preserve parkedPagesCacheRefs in multi-windowretain_user_messages, pruneTurnDiffs,ContextWindows,pages::{histories, gaps, bridges},Ends/Recall,inbox_payload_store, closed pluginServer:Resourceentries, and release closed file tabs viaSessionFiles::close_file.mimallocworker purging (apps/desktop/src/lib.rs,pages/worker.rs,crates/opencode-kit/src/client.rs,model/tool.rs,crates/browser-pane/src/transport.rs): Tunemimalloc3.3 (purge_delay = 250 ms,page_reclaim_on_free = 1), collect worker thread heaps before parking, shrink SSE (opencode-kit) and browser sidecar (browser-pane) line buffers after large frames, and drop redundantmetadata["output"]onceopencode-kit.outputis stored.