Repository navigation
perf: drop background tabs' back/forward cache and ask before sending a form again - #114
Merged
Merged
Conversation
A WebKit tab left in the background for a minute ends the web processes WebKit keeps for its earlier pages after cross-site navigations. The shown page, its form input and its history stay; Back loads the earlier page again. No tab sleeps any sooner. One WKWebView after five cross-site loads went from 4 web processes and 586 MB to 2 and 377 MB. CEF, WebKitGTK and Android WebView have no per-view call for it (documented gaps); iOS is in the port backlog. Signed-off-by: rgxdev <hello@d-aaron.dev>
…gain Back/forward cache: - engine::lifecycle::BackForwardTrim decides which live tabs drop their cache: once per stay off screen, after BACK_FORWARD_IDLE (60 s). Shells stamp the tabs they leave on a switch, so a tab viewed between two checks waits a full minute. - macOS uses it instead of the inline idle check; iOS sends a new dropBackForwardCache command from a minute timer, and Android ignores it (its WebView has no such call). Form resubmission: - With the cache dropped, WebKit loads a POST result again on Back, Forward or Reload as FormResubmitted and would send the form again. On macOS and iOS that load now waits for a Tarn prompt (Send Again or Cancel, Cancel by default) after every Shield and network check. - Only the user's own history step asks; a page's history.back() or a swipe cancels the load and shows a notice. - Linux, which still sends it silently, is in the port backlog. Signed-off-by: rgxdev <hello@d-aaron.dev>
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
MadebyLeopold
previously approved these changes
Nov 24, 2026
…ory-use Signed-off-by: rgxdev <hello@d-aaron.dev> # Conflicts: # docs/port-backlog.md
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.
Closes #
What changed
Tarn reached about 4.4 GB with many tabs open. Measured on a running Tarn: the shell 374 MB, WebKit's GPU process 321 MB, and 8 WebContent processes at about 3.6 GB. Sleeping a tab already frees its process: in a throwaway build with live tabs capped at 3, 10 tabs left 4 processes. Without sleeping tabs any sooner, this PR cuts the memory WebKit keeps for pages a tab has already left:
engine::lifecycle::BACK_FORWARD_IDLE(60 s) calls WebKit's private_clearBackForwardCacheonce per stay off screen. The call is guarded byrespondsToSelector, like the existing_webProcessIdentifieruse. This ends the suspended WebContent processes WebKit keeps for earlier pages after cross-site navigations. The shown page, its form input and its history stay; Back loads the earlier page again.engine::lifecycle::BackForwardTrimmakes the decision (shared core, unit-tested); macOS calls it from the minute tick, and mobile from a minute timer through a newdropBackForwardCacheweb-view command. Measured with one WKWebView after 5 cross-site loads: 4 WebContent processes / 586 MB before, 2 / 377 MB after.FormResubmitted, and allowing that sends the form again. A harness confirmed it: the server logged 2 POSTs when allowed and 1 when cancelled. That decision now waits for a newPromptKind::ResendFormprompt (" would get your form again"), with Send Again (danger colour, click-guarded) and Cancel (default). The prompt comes after every gate, Shield, S10 and level check. Only the user's own history step asks. A page'shistory.back()or a swipe cancels the load and showsnav_policy::RESEND_STOPPED, so a page cannot make Tarn ask about another site's form. Chromium tabs (Windows) show Chromium's own resubmission page; Android's WebView declines resubmission by default.An earlier attempt changed the sleep policy (6 live tabs, a 5-minute budget, a 768 MB per-tab ceiling). It was dropped because it partly reversed the gentler sleeping from #73 and could lose typed input.
How it was tested
Checks run, and checks not run (and why):
cargo fmt --all --check,cargo clippy --all-targets --locked -- -D warnings,cargo test --locked: pass.mobile/: fmt, clippy, test: pass.cargo clippy --target aarch64-apple-ios-sim --all-targets --locked -- -D warnings: pass.engine::lifecycletests forBackForwardTrim(once per stay, the split, a tab left between two checks, a tab that slept and woke),mobile/app/tests/features.rs(split panes stay, a tab left between checks waits a minute), and thebrowser_core::promptstext.canGoBackstays true, Back after the drop sends BackForward then FormResubmitted, and Reload of a POST result sends FormResubmitted directly.TARN_DATA_DIRin a temp folder) with 3 tabs past two ticks: no crash.linux/(WebKitGTK/GTK not installed on this Mac),mobile/android/build.sh(needs thenshpackager), Windows (no MSVC). CI covers these. The resend prompt itself was not clicked through in the GPUI app; its WebKit inputs were verified with the harness.Clients covered (the others get a
docs/port-backlog.mdentry):docs/windows-plan.md§8), WebKitGTK (docs/nsh-plan.md), Android WebView (docs/mobile-plan.md). None of them has a per-view back/forward cache flush.docs/port-backlog.mdentry. A maintainer may want this treated as a protection that lands everywhere (AGENTS rule 8). Linux drops no cache, so this change makes the Linux case no more frequent.Protected paths (
.github/CODEOWNERS), dependencies, pins or checks changed, and why:docs/:mobile-plan.md,nsh-plan.md,windows-plan.md(gaps),port-backlog.md(Linux entry). No dependency, pin, lockfile or CI changes.Threat model: S1 (no page-to-shell bridge: none added; the prompt is shell UI driven by WebKit's navigation delegate), S5/S10 (every navigation check runs before the prompt; accepting runs the same steps as an allowed load), S21 (each new
unsafestates its invariant). The held WebKit decision is answered exactly once on every path: confirm, cancel, page-started, a dropped prompt (which declines), or a closed tab.Anything done differently from the guidelines in
AGENTS.mdorCONTRIBUTING.md, and why:Uses WebKit SPI (
_clearBackForwardCache), the same pattern as the existing_webProcessIdentifierand_hideFindUIcalls; it does nothing where the selector is missing.Known limits: iframe form resubmissions still pass silently (unchanged behaviour). Mobile prompts have no click-guard delay (applies to all mobile prompts, unchanged).
I read and understand every line and sign it off as its author (
git commit -s)Any AI agent used kept the hard rules in
AGENTS.mdNo secrets, credentials or personal data in the diff