S062: memory saver sliders, resting tab icons, last_shown stamped when a tab is left
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
parent
09233cdaf3
commit
2f53bdec8f
9 changed files with 122 additions and 20 deletions
|
|
@ -13,12 +13,12 @@ User report: memory saver / "Freeze background tabs" doesn't catch. Check that h
|
|||
- `src/ui/widgets.rs` (existing slider, as used by Interface size)
|
||||
|
||||
## Steps
|
||||
- [ ] Check with a selftest run and short times (env or settings override, e.g. 1 min): does `slow_tick` run often enough, is `last_shown` right for tabs never shown, are lazily restored/pinned/audible tabs skipped as intended; does the web process count/PSS drop after unload. Fix what's wrong.
|
||||
- [ ] Tab strip: unloaded tab = dimmed favicon (+ tooltip "Unloaded to save memory"), frozen = lighter dim; cleared when shown.
|
||||
- [ ] Settings: Memory saver and Freeze each a slider (Off … 4 h for unload, Off … 60 min for freeze; snapping steps, value label "Off"/"15 min"/"1 h"), stored in the existing `discard_min`/`freeze_min`.
|
||||
- [ ] Unit test for `tab_rest_minutes` with the new ranges.
|
||||
- [ ] `tests/smoke/rest.txt` (offline): 3 tabs, short times, assert `has_web` false / `frozen` true on hidden ones, shot of the strip dark and light. Run it only (D-048).
|
||||
- [ ] PROGRESS entry, INDEX line, tracker, commit `S062: …`, push.
|
||||
- [x] Check with a selftest run and short times (env or settings override, e.g. 1 min): does `slow_tick` run often enough, is `last_shown` right for tabs never shown, are lazily restored/pinned/audible tabs skipped as intended; does the web process count/PSS drop after unload. Fix what's wrong.
|
||||
- [x] Tab strip: unloaded tab = dimmed favicon (+ tooltip "Unloaded to save memory"), frozen = lighter dim; cleared when shown.
|
||||
- [x] Settings: Memory saver and Freeze each a slider (Off … 4 h for unload, Off … 60 min for freeze; snapping steps, value label "Off"/"15 min"/"1 h"), stored in the existing `discard_min`/`freeze_min`.
|
||||
- [x] Unit test for `tab_rest_minutes` with the new ranges.
|
||||
- [x] `tests/smoke/rest.txt` (offline): 3 tabs, short times, assert `has_web` false / `frozen` true on hidden ones, shot of the strip dark and light. Run it only (D-048).
|
||||
- [x] PROGRESS entry, INDEX line, tracker, commit `S062: …`, push.
|
||||
|
||||
## End criteria
|
||||
- `cargo test` green; `rest.txt` exit 0; strip shot shows dimmed tabs; settings shot shows sliders.
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ Dropped with Servo (D-032): S011, S029, S030, S032, S033, S037, S038.
|
|||
- [x] [S059 — Tab lifecycle: stuck pages, nacre:// pages unloading, script message handler](09%20Fix%20round/S059-tab-lifecycle.md) · Opus high
|
||||
- [x] [S060 — Picture in picture keeps working (focus)](09%20Fix%20round/S060-pip-focus.md) · Opus medium · 🧑
|
||||
- [x] [S061 — A site's own context menu wins; video clicks don't open ads](09%20Fix%20round/S061-site-menus-clickthrough.md) · Opus medium · 🧑
|
||||
- [ ] [S062 — Memory saver that actually unloads, sliders, resting tab icons](09%20Fix%20round/S062-memory-saver.md) · Sonnet high
|
||||
- [x] [S062 — Memory saver that actually unloads, sliders, resting tab icons](09%20Fix%20round/S062-memory-saver.md) · Sonnet high
|
||||
- [ ] [S063 — Lock down nacre:// pages; passwords unlock on every open](09%20Fix%20round/S063-nacre-pages-lockdown.md) · Opus medium
|
||||
- [ ] [S064 — History flyout, bookmark flyout on tab switch, About lists nacre:// pages](09%20Fix%20round/S064-history-flyout-about.md) · Sonnet high
|
||||
- [ ] [S065 — Custom download manager by name and port](09%20Fix%20round/S065-custom-manager-port.md) · Sonnet high
|
||||
|
|
|
|||
|
|
@ -490,6 +490,13 @@ Later: S010 list: user checks the Discord icon with their own client (the Discor
|
|||
- Not done: 🧑 the real site after the fix was not reloaded (plan allows one hidden load; it was used to find the cause): the user should open a video there and click the player once to confirm. No visible run; YouTube/Discord menus not rechecked live.
|
||||
- Later: a link clicked inside a frame still goes through the tab's policy (S050 note); WebKit treats `evaluate_javascript` window.open as a user gesture.
|
||||
|
||||
## S062 — Memory saver sliders and resting tab icons (2026-11-18)
|
||||
- Unloading: `slow_tick` already ran (30 s) and skipped the right tabs (active, audible, PiP, kept hosts, pinned for unload). Real defect: `last_shown` is stamped only when the active tab is laid out, so a tab left active a long time could be unloaded at the first tick after switching away; `select_tab` now stamps the tab being left. Hidden `rest.txt` confirms frozen → unloaded (`has_web` false) → reloaded on select.
|
||||
- Strip: unloaded tab = favicon at 45 % + tooltip "Unloaded to save memory"; frozen = 70 % + "Resting in the background"; back to full when shown.
|
||||
- Settings: Memory saver slider Off/5 min/15/30/1 h/2 h/4 h, Freeze slider Never/1/2/5/10/15/30/60 min (snapping, stored in `discard_min`/`freeze_min`); labels in the row text.
|
||||
- `NACRE_REST_UNIT_SECS` makes a rest "minute" shorter (smoke only). Test: `tab_rest_minutes` ranges; `tests/smoke/rest.txt` (`NACRE_REST_UNIT_SECS=2`) exit 0. `cargo test` 89 + webext 1.
|
||||
- Not done: PSS drop after unload not measured here (`integ-perf.txt` has the memory numbers); no visible run.
|
||||
|
||||
## Later
|
||||
- A link followed inside a frame still goes through the tab's navigation policy (WebKit's GTK API has no frame info; S050).
|
||||
- file:// media outside the XDG user folders doesn't play (WebKit sandbox, D-043).
|
||||
|
|
|
|||
|
|
@ -1058,6 +1058,10 @@ impl App {
|
|||
if let Some(win) = self.windows.get_mut(&window)
|
||||
&& index < win.tabs.len()
|
||||
{
|
||||
// The tab being left starts resting now, not when it was last drawn.
|
||||
if let Some(old) = win.tabs.get_mut(win.active) {
|
||||
old.last_shown = std::time::Instant::now();
|
||||
}
|
||||
win.active = index;
|
||||
win.ui.omnibox_edit = win.tabs[index].draft.clone();
|
||||
win.ui.close_popups();
|
||||
|
|
|
|||
|
|
@ -1209,7 +1209,7 @@ impl App {
|
|||
self.save_session();
|
||||
self.flush_stores();
|
||||
}
|
||||
if now.duration_since(self.last_slow) >= Duration::from_secs(30) {
|
||||
if now.duration_since(self.last_slow) >= Duration::from_secs((crate::perf::rest_unit_secs() / 2).clamp(1, 30)) {
|
||||
self.last_slow = now;
|
||||
self.slow_tick();
|
||||
}
|
||||
|
|
@ -1281,7 +1281,7 @@ impl App {
|
|||
if i == active || tab.web.is_none() || tab.audible() || tab.pip_size.is_some() || settings.keeps_active(&tab.host()) || tab.pinned && discard == 0 {
|
||||
continue;
|
||||
}
|
||||
let idle = now.duration_since(tab.last_shown).as_secs() / 60;
|
||||
let idle = now.duration_since(tab.last_shown).as_secs() / crate::perf::rest_unit_secs();
|
||||
if discard > 0 && idle >= discard as u64 && !tab.pinned {
|
||||
// Unload: forget the web view, keep the address to load it again when shown.
|
||||
tab.pending_url = Some(tab.url.clone());
|
||||
|
|
|
|||
26
src/perf.rs
26
src/perf.rs
|
|
@ -131,7 +131,33 @@ pub fn tab_rest_minutes(settings: &Settings) -> (u32, u32) {
|
|||
(freeze, discard)
|
||||
}
|
||||
|
||||
/// Seconds in one rest minute: 60, or `NACRE_REST_UNIT_SECS` (smoke tests count a minute in a few seconds).
|
||||
pub fn rest_unit_secs() -> u64 {
|
||||
std::env::var("NACRE_REST_UNIT_SECS").ok().and_then(|v| v.parse().ok()).filter(|&v| v > 0).unwrap_or(60)
|
||||
}
|
||||
|
||||
/// Whether animations (new tab background, ad removal, artwork spin) should stand still.
|
||||
pub fn still(settings: &Settings) -> bool {
|
||||
settings.perf.still_ntp || lite(settings) || energy_saver(settings)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn rest_minutes_follow_the_sliders_and_low_memory_caps_them() {
|
||||
let mut s = Settings::default();
|
||||
s.perf.lite = AutoOnOff::Off;
|
||||
s.perf.energy = EnergySaver::Off;
|
||||
s.perf.freeze_min = 60;
|
||||
s.perf.discard_min = 0;
|
||||
assert_eq!(tab_rest_minutes(&s), (60, 0));
|
||||
s.perf.lite = AutoOnOff::On;
|
||||
s.perf.discard_min = 240;
|
||||
assert_eq!(tab_rest_minutes(&s), (1, 15));
|
||||
s.perf.freeze_min = 0;
|
||||
s.perf.discard_min = 0;
|
||||
assert_eq!(tab_rest_minutes(&s), (0, 0));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -269,6 +269,9 @@ fn tab(ui: &mut Ui, f: &mut Frame, index: usize, rect: Rect, dragged: bool, drop
|
|||
let favicon = t.favicon.as_ref().map(|t| t.id());
|
||||
let internal = t.page.is_some();
|
||||
let active = index == *f.active;
|
||||
// Resting tabs look dimmer, as in Chromium: unloaded (no web view) more than frozen.
|
||||
let (unloaded, frozen) = (!internal && t.web.is_none(), t.frozen);
|
||||
let rest_dim = if unloaded { 0.45 } else if frozen { 0.7 } else { 1.0 };
|
||||
let response = ui.interact(rect, Id::new(("tab", tab_id)), Sense::click_and_drag());
|
||||
let (amount, press) = state_layer(ui, &response);
|
||||
let selected = theme::effect(&ctx, Id::new(("tab-on", tab_id)), active);
|
||||
|
|
@ -300,11 +303,11 @@ fn tab(ui: &mut Ui, f: &mut Frame, index: usize, rect: Rect, dragged: bool, drop
|
|||
if load < 1.0 {
|
||||
let size = 16.0 * (1.0 - 0.4 * load);
|
||||
let mut painter = ui.painter().clone();
|
||||
painter.set_opacity(1.0 - load);
|
||||
painter.set_opacity((1.0 - load) * rest_dim);
|
||||
if let Some(texture) = favicon {
|
||||
painter.image(texture, Rect::from_center_size(icon_center, Vec2::splat(size)), Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::WHITE);
|
||||
} else {
|
||||
icon(ui, icon_center, if internal { icons::TAB } else { icons::PUBLIC }, size, active, content.gamma_multiply(1.0 - load));
|
||||
icon(ui, icon_center, if internal { icons::TAB } else { icons::PUBLIC }, size, active, content.gamma_multiply((1.0 - load) * rest_dim));
|
||||
}
|
||||
}
|
||||
let hovered = response.hovered() || ui.rect_contains_pointer(rect);
|
||||
|
|
@ -331,7 +334,8 @@ fn tab(ui: &mut Ui, f: &mut Frame, index: usize, rect: Rect, dragged: bool, drop
|
|||
ui.painter().galley(pos2(left, cy - galley.size().y / 2.0), galley, content);
|
||||
}
|
||||
}
|
||||
let response = response.on_hover_text(format!("{title}\n{url}"));
|
||||
let note = if unloaded { "\nUnloaded to save memory" } else if frozen { "\nResting in the background" } else { "" };
|
||||
let response = response.on_hover_text(format!("{title}\n{url}{note}"));
|
||||
if command.is_some() {
|
||||
return command;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -674,6 +674,27 @@ fn toolbar(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
|||
});
|
||||
}
|
||||
|
||||
/// Snap points of the memory saver and freeze sliders, in minutes (0 = off).
|
||||
const UNLOAD_STEPS: &[u32] = &[0, 5, 15, 30, 60, 120, 240];
|
||||
const FREEZE_STEPS: &[u32] = &[0, 1, 2, 5, 10, 15, 30, 60];
|
||||
|
||||
fn rest_label(minutes: u32, off: &str) -> String {
|
||||
match minutes {
|
||||
0 => off.to_owned(),
|
||||
m if m % 60 == 0 => format!("{} h", m / 60),
|
||||
m => format!("{m} min"),
|
||||
}
|
||||
}
|
||||
|
||||
/// A slider over `steps` that holds the nearest step (a stored value between two steps shows at the nearer one).
|
||||
fn rest_slider(ui: &mut Ui, minutes: &mut u32, steps: &[u32]) {
|
||||
let at = steps.iter().enumerate().min_by_key(|(_, s)| s.abs_diff(*minutes)).map_or(0, |(i, _)| i);
|
||||
let mut v = at as f32;
|
||||
if settled_slider(ui, &mut v, 0.0..=(steps.len() - 1) as f32, 200.0, &|v| rest_label(steps[v.round() as usize], "Off")) {
|
||||
*minutes = steps[v.round() as usize];
|
||||
}
|
||||
}
|
||||
|
||||
fn performance(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
||||
section(ui, "Memory");
|
||||
card(ui, |ui| {
|
||||
|
|
@ -690,14 +711,10 @@ fn performance(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
|
|||
});
|
||||
section(ui, "Tabs");
|
||||
card(ui, |ui| {
|
||||
row(ui, "Memory saver", "Unloads tabs you haven't looked at; they load again when you return", |ui| {
|
||||
let opts: &[(u32, &str)] = &[(0, "Off"), (15, "15 min"), (30, "30 min"), (60, "1 h"), (120, "2 h")];
|
||||
segmented(ui, &mut s.perf.discard_min, opts)
|
||||
});
|
||||
limited_row(ui, "Freeze background tabs", "Marks hidden tabs as frozen after a while", "WebKit already stops their drawing and slows their timers at once; it has no way to stop scripts or free memory, so unload for that", |ui| {
|
||||
let opts: &[(u32, &str)] = &[(0, "Never"), (1, "1 min"), (5, "5 min"), (15, "15 min")];
|
||||
segmented(ui, &mut s.perf.freeze_min, opts)
|
||||
});
|
||||
let saver = &mut s.perf.discard_min;
|
||||
row(ui, "Memory saver", &format!("Unloads tabs you haven't looked at; they load again when you return. {}", rest_label(*saver, "Off")), |ui| rest_slider(ui, saver, UNLOAD_STEPS));
|
||||
let freeze = &mut s.perf.freeze_min;
|
||||
limited_row(ui, "Freeze background tabs", &format!("Marks hidden tabs as frozen after a while. {}", rest_label(*freeze, "Never")), "WebKit already stops their drawing and slows their timers at once; it has no way to stop scripts or free memory, so unload for that", |ui| rest_slider(ui, freeze, FREEZE_STEPS));
|
||||
wide_row(ui, "Always keep these sites active", "Never unloaded or frozen", |ui| {
|
||||
host_chips(ui, &mut s.perf.keep_active, "Remove", "No sites yet");
|
||||
ui.end_row();
|
||||
|
|
|
|||
44
tests/smoke/rest.txt
Normal file
44
tests/smoke/rest.txt
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# Memory saver (S062): hidden tabs are marked frozen, then unloaded; the strip dims them and the settings use sliders.
|
||||
# Offline. Run: NACRE_REST_UNIT_SECS=2 tools/smoke.sh tests/smoke/rest.txt <outdir> (a rest "minute" counts 2 s, checked every second).
|
||||
wait 3
|
||||
set /theme/mode "dark"
|
||||
set /perf/lite "off"
|
||||
set /perf/freeze_min 1
|
||||
set /perf/discard_min 4
|
||||
open @PAGES@/hello.html
|
||||
waitload 30
|
||||
newtab @PAGES@/color.html
|
||||
waitload 30
|
||||
newtab @PAGES@/favicon-red.html
|
||||
waitload 30
|
||||
cmd select 0
|
||||
wait 4
|
||||
status frozen
|
||||
expect /tabs/1/frozen true
|
||||
expect /tabs/2/frozen true
|
||||
expect /tabs/0/frozen false
|
||||
expect /tabs/1/has_web true
|
||||
shot strip-frozen-dark
|
||||
wait 10
|
||||
status unloaded
|
||||
expect /tabs/0/has_web true
|
||||
expect /tabs/1/has_web false
|
||||
expect /tabs/2/has_web false
|
||||
shot strip-unloaded-dark
|
||||
set /theme/mode "light"
|
||||
wait 1
|
||||
shot strip-unloaded-light
|
||||
# Showing one loads it again and clears the marks.
|
||||
cmd select 1
|
||||
wait 4
|
||||
status restored
|
||||
expect /tabs/1/has_web true
|
||||
expect /tabs/1/frozen false
|
||||
page nacre://settings/performance
|
||||
wait 1
|
||||
shot sliders-light
|
||||
set /theme/mode "dark"
|
||||
wait 1
|
||||
shot sliders-dark
|
||||
status done
|
||||
quit
|
||||
Loading…
Reference in a new issue