feat: auto-hibernate inactive instances to reclaim memory#10
Open
Teamingzooper wants to merge 1 commit into
Open
feat: auto-hibernate inactive instances to reclaim memory#10Teamingzooper wants to merge 1 commit into
Teamingzooper wants to merge 1 commit into
Conversation
Adds an opt-in setting that destroys the embedded WebContentsView for any non-active instance idle longer than a configured threshold (5–480 minutes). The instance keeps its sidebar entry, gets a 💤 indicator, and re-activating rebuilds the view from scratch (slow first activation accepted as the cost of the freed memory). Big win for users with 8+ instances — each Chromium tab eats real RAM, and a hibernated instance frees most of that. Implementation: - New `hibernateAfterMinutes?: number` on appStateSchema (range 5–480, undefined/0 = disabled). - SettingsService.setHibernateAfterMinutes() with normalisation. - ViewService tracks lastActiveAt: Map<id, ms> seeded on ensure(), updated on every activate(). A new 60-second interval timer runs runHibernationSweep(): iterates views, tears down any with (id !== activeId && lastActiveAt < now - minutes*60_000). Emits bus event 'instance:hibernated'. - ensure() checks a hibernatedIds set; if the id was previously hibernated, emits 'instance:woken' on the recreated view. - destroy() (manual remove) clears both lastActiveAt and hibernatedIds. - IpcService forwards both new bus events as nexus:instance:hibernated and nexus:instance:woken to the main renderer window. - preload exposes onInstanceHibernated, onInstanceWoken, and setHibernateAfterMinutes. - Renderer store tracks hibernatedInstances: Record<id, true>. - Sidebar renders a 💤 next to hibernated instance names. - Settings → General gains a Performance section with a toggle (default off; defaults to 60 min when first enabled) and a numeric input. The default is OFF — opt-in to avoid surprising users who don't realise their open conversation could lose scroll/draft state when its view is destroyed. The active instance is never hibernated. 178/178 unit tests pass, typecheck + build clean.
This was referenced May 19, 2026
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.
Summary
Big win for users with 8+ instances open: an opt-in setting that destroys the embedded WebContentsView for any non-active instance that's been idle longer than a configured threshold (default 60 min when enabled, range 5–480 min). The instance keeps its sidebar entry, gets a 💤 indicator, and re-activating it rebuilds the view from scratch.
Why
Each embedded WebContentsView is a full Chromium tab — easily 100–300 MB of RAM each. A user with 8 instances (work WhatsApp, personal WhatsApp, work Slack, personal Slack, Telegram, Messenger, Teams, Instagram) is sitting at 1–2 GB just for Nexus's webviews, even when they're only actively using one. Hibernation can reclaim most of that.
What you give up by enabling it
When an instance hibernates, its WebContentsView is destroyed. The instance loses:
Hence opt-in by default. The toggle is in Settings → General → Performance with a clear description of the tradeoff.
Design choices
Architecture
Same main → bus → IPC → renderer pattern as the rest of this stack:
Test plan
🤖 Generated with Claude Code