Repository navigation
perf(plugins,restore): sleep unused plugins while active and debounce restore.persist - #2559
Merged
Merged
Conversation
…ety and immediate draft journaling
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.
Fixes two active-session overhead sources seen in live
v0.0.0-dev-543traces (opencode-perf-20261206-043341,043755,044001;runningPluginCount: 16andlastRestReclaim: nullin all three) and removes four small monotonic allocations.Root Cause
dormant::sleep_unusedran only fromApp::on_rest(10 s with zero frames on Home with zero tabs). During continuous 24/7 work, all 16 bundled PsychoScript VMs stayed resident indefinitely.restore.persistran up to 102×/sec (277×in13.3 s,91.5 mstotal,max 1.233 msin043755;81×in12.6 sin044001):270of the277hits occurred across a2.65 s(305-frame) burst of input frames (pollN: 2, avg331 µs).poll_restore_versionedhad zero debounce, so everyRestoreVersionsbump (side/bottom/split/sidebar resize drags, composer typing, or session updates) immediately cloned open tabs, builtserde_json::Valuetrees forside, and ranside_stamp_where(&is_rest)across every historical session.Changes
1. Periodic active-window plugin dormancy (
apps/desktop/src/plugin_host/runtime/dormant.rs)SweepPhase(Idle | Armed { due }) andWarmth(Warm { since, cooldown } | Slept { at, cooldown }) state machines stored inCell/RefCellso polls never dirtyTracked<PluginHost>.dormant::pollevery 60 s with zero idle wake timers (App::on_restremains undisturbed). Sleeps at most 1 unused, non-busy, cold (>= 120 s) bundled plugin VM per interval and runspurge_free_pages_soft()on native targets.want_now), its cooldown doubles up to 960 s.busy()and addedshown_in_window()to protect openperfmonitors, visibledebugbar, active-route slots/pills/open side & bottom panel tabs/narrow drawer, New tab dynamic launchers,file_viewerswhenfileis open,titlebar_items, open aux windows, live embeds, host prompt dialogs, Plugin Inspector targets, in-flight MCP tool calls, pending requests, active plugin themes, active model badges / Go usage, and remembered/listed/pending server sources (ssh/wsl).plugin.<id>.wokeperf-mark strings inWAKE_MARKSinstead of callingBox::leakon every wake.stateDiagram-v2 [*] --> Warm: Started (cooldown = 120s) Warm --> Warm: InUse (refresh since) Warm --> Warm: IdleCheck (elapsed < cooldown) Warm --> Slept: IdleCheck (elapsed >= cooldown, 1/sweep) Slept --> Warm: Started within 15s (cooldown *= 2, max 960s) Slept --> Warm: Started after 15s (cooldown = 120s)2. Debounced
restore.persist(features/restore/,apps/desktop/src/workspace/lifecycle/restore.rs)PersistDebounce(Clean | Pending { seen, first_dirty, due, wake_armed }) infeatures/restore/src/state.rs(stored inCell, zeroRESTOREslot bumps).poll_restore_debouncedcoalesces scheduledrestore.persistticks with a 1.0 s trailing settle delay and 2.0 s max wait while keeping initial/hydration flushes, crash-recoveryset_active_exit_session, and draft blob upload/arrival checks immediate.tick::visibility),save_on_close, andsave_on_quitstill call immediatepoll_restore, which stepsPersistDebounceEvent::Flushedand writes synchronously with zero lost state.AtomicBool::swap(false, AcqRel)checks behindload(Ordering::Acquire)incopies.rs,draft_doc.rs, andundo.rs.stateDiagram-v2 [*] --> Clean Clean --> FlushNow: First poll or hydration change Clean --> Pending: Version changed (due = now + 1s) Pending --> Pending: Changed (due = min(now + 1s, first + 2s)) Pending --> FlushNow: now >= due Pending --> Clean: Flushed (hide/close/quit) or matched FlushNow --> Clean3. Bounded maps & cache audit
features/restore/src/parked.rs&lib.rs: Skip cloning empty no-historyTextEdits intoRestore::editson route switches/closes and prune non-draft undo-only entries pastMAX_KEPT_EDITS = 32.features/restore/src/draft_doc.rs: Prune deadWeak<[u8]>entries fromBlobs::idson insert oncelen >= 64.features/restore/src/preview.rs: Retain only active/open-tab entries inPreviewsoncelen > 64.session_links/mod.rs(50 × 20LRU/FIFO),code_node.rs(64entries /4 MiB),custom_diff.rs(64docs /16 MiBper plugin, reaped on VM stop/reload).