Skip to content

perf: add Memory Saver with tab suspension and exclusion list#165

Open
Ayush-Vish wants to merge 20 commits intop2plabsxyz:mainfrom
Ayush-Vish:feature/memory-saver
Open

perf: add Memory Saver with tab suspension and exclusion list#165
Ayush-Vish wants to merge 20 commits intop2plabsxyz:mainfrom
Ayush-Vish:feature/memory-saver

Conversation

@Ayush-Vish
Copy link
Copy Markdown
Contributor

@Ayush-Vish Ayush-Vish commented Mar 23, 2026

Related Issue (if any)

Closes: #164
image

image

Describe the add-ons or changes you've made

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, local variables)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Checklist:

  • My code follows the "contribution guidelines" of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly wherever it was hard to understand.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.

Screenshots (Only for Front End and UI/UX Designers)

Original Updated
Original Screenshot Updated Screenshot

Copilot AI review requested due to automatic review settings March 23, 2026 12:13
@Ayush-Vish Ayush-Vish changed the title feat: implement peersky://settings/performance to free up the inactive tabs feat(performance): Add Memory Saver with tab suspension and exclusion list Mar 23, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements a new “Memory Saver” performance feature in PeerSky settings and tab UI to suspend inactive tabs and visually indicate sleeping tabs, with an exclusions list to keep selected sites active.

Changes:

  • Added new settings keys (memorySaverEnabled, memorySaverExclusions) and broadcast updates to renderer windows.
  • Implemented tab suspension/wake-up logic in the tab bar, including navigation-history capture/restore and hover-card memory usage updates.
  • Added a new “Performance” section in Settings UI with toggle + exclusions management, plus sleeping-tab styling.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/settings-manager.js Adds defaults/validation and emits memory-saver-changed on updates.
src/pages/tab-bar.js Implements suspend/wake logic, idle checking, exclusions matching, and hover-card async memory lookup.
src/pages/settings.html Adds Performance section UI and navigation entry.
src/pages/static/js/settings.js Wires up Memory Saver toggle + exclusions list UI behavior.
src/pages/theme/index.css Adds sleeping-tab visual treatment (favicon ring/title dimming) and hides the old emoji indicator.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/pages/tab-bar.js
Comment thread src/pages/tab-bar.js
Comment thread src/pages/tab-bar.js Outdated
Comment thread src/pages/tab-bar.js Outdated
Comment on lines +139 to +157

// Save history
try {
const { ipcRenderer } = require("electron");
const webContentsId = webview.getWebContentsId();
tab.savedNavigation = ipcRenderer.sendSync('get-tab-navigation', webContentsId);
} catch (e) {
console.warn("Failed to save nav history for sleeping tab", e);
}

// Destroy webview
webview.remove();
this.webviews.delete(tabId);

// Unregister extension cleanly
try {
const { ipcRenderer } = require("electron");
ipcRenderer.invoke('extensions-unregister-webview', webview.getWebContentsId()).catch(() => {});
} catch (e) {}
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suspendTab() removes the webview from the DOM before invoking extensions-unregister-webview using webview.getWebContentsId(). Depending on Electron/webview lifecycle timing, this can throw or return an invalid ID, leaving the extension system registered for a destroyed view. Capture webContentsId once before removing the webview and reuse it for both navigation save + unregister.

Suggested change
// Save history
try {
const { ipcRenderer } = require("electron");
const webContentsId = webview.getWebContentsId();
tab.savedNavigation = ipcRenderer.sendSync('get-tab-navigation', webContentsId);
} catch (e) {
console.warn("Failed to save nav history for sleeping tab", e);
}
// Destroy webview
webview.remove();
this.webviews.delete(tabId);
// Unregister extension cleanly
try {
const { ipcRenderer } = require("electron");
ipcRenderer.invoke('extensions-unregister-webview', webview.getWebContentsId()).catch(() => {});
} catch (e) {}
// Capture webContentsId once while the webview is still alive
let webContentsId = null;
try {
webContentsId = webview.getWebContentsId();
} catch (e) {
console.warn("Failed to get webContentsId for sleeping tab", e);
}
// Save history
if (webContentsId != null) {
try {
const { ipcRenderer } = require("electron");
tab.savedNavigation = ipcRenderer.sendSync('get-tab-navigation', webContentsId);
} catch (e) {
console.warn("Failed to save nav history for sleeping tab", e);
}
}
// Destroy webview
webview.remove();
this.webviews.delete(tabId);
// Unregister extension cleanly
if (webContentsId != null) {
try {
const { ipcRenderer } = require("electron");
ipcRenderer
.invoke('extensions-unregister-webview', webContentsId)
.catch(err => {
console.warn("Failed to unregister webview extensions for sleeping tab", err);
});
} catch (e) {
console.warn("Error while requesting webview extension unregister for sleeping tab", e);
}
}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment addressed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in fc0187e

Comment thread src/pages/tab-bar.js
Comment thread src/pages/tab-bar.js
Comment thread src/pages/settings.html Outdated
Comment thread src/pages/settings.html Outdated
Comment thread src/pages/static/js/settings.js Outdated
Comment thread src/pages/tab-bar.js Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/pages/settings.html Outdated
Comment thread src/pages/tab-bar.js Outdated
Comment thread src/pages/tab-bar.js Outdated
Comment thread src/pages/settings.html Outdated
Comment thread src/pages/tab-bar.js
Comment thread src/pages/tab-bar.js Outdated
Comment thread src/pages/tab-bar.js Outdated
Comment thread src/pages/theme/index.css
Comment thread src/pages/static/js/settings.js Outdated
@akhileshthite akhileshthite changed the title feat(performance): Add Memory Saver with tab suspension and exclusion list perf: add Memory Saver with tab suspension and exclusion list Mar 23, 2026
@akhileshthite akhileshthite added enhancement New feature or request electron Related to electron.js labels Mar 23, 2026
Copy link
Copy Markdown
Member

@akhileshthite akhileshthite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start!
I have comments related benchmark details, navigation concerns, and UI suggestions.

Comment thread src/pages/tab-bar.js
Comment thread src/pages/tab-bar.js
Comment thread src/pages/settings.html Outdated
@akhileshthite
Copy link
Copy Markdown
Member

I just realized that we don't have Tabs.md in docs/, IIRC @Ankesh2004 was working on it when he originally shipped tabs.

@Ayush-Vish It would be good to include memory saver there.

Copy link
Copy Markdown
Member

@akhileshthite akhileshthite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly related to Doc, UI, and a missing unaddressed comment.

Comment thread docs/Tabs.md
Comment thread docs/Tabs.md
Comment thread docs/Tabs.md
---

## 6. Memory Saver

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Display SS, save as ./docs/images/peersky-memory-saver.png. Keep width width="800".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need visuals of 10 cropped open tabs. Before and After benchmark graph. As I mentioned in the linked comment, we can also compare Chrome's memory saver performance with ours in a graph.

(#165)

Comment thread docs/Tabs.md
Comment thread docs/Tabs.md
Comment thread docs/Tabs.md Outdated
Comment thread src/pages/settings.html Outdated
Comment thread src/pages/tab-bar.js
Comment thread src/pages/tab-bar.js Outdated
Comment on lines +139 to +157

// Save history
try {
const { ipcRenderer } = require("electron");
const webContentsId = webview.getWebContentsId();
tab.savedNavigation = ipcRenderer.sendSync('get-tab-navigation', webContentsId);
} catch (e) {
console.warn("Failed to save nav history for sleeping tab", e);
}

// Destroy webview
webview.remove();
this.webviews.delete(tabId);

// Unregister extension cleanly
try {
const { ipcRenderer } = require("electron");
ipcRenderer.invoke('extensions-unregister-webview', webview.getWebContentsId()).catch(() => {});
} catch (e) {}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment addressed?

Comment thread src/main.js
Copy link
Copy Markdown
Member

@akhileshthite akhileshthite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing!
We're almost there :D

Comment thread docs/Tabs.md Outdated
Comment thread src/settings-manager.js Outdated
Comment thread src/pages/tab-bar.js Outdated
Comment thread src/pages/static/js/settings.js Outdated
Comment thread src/pages/settings.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

electron Related to electron.js enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Memory Saver — suspend inactive tabs to reduce RAM usage

3 participants