Skip to content

Restart the mail viewer's process when nothing is on screen - #297

Merged
g0shed merged 4 commits into
mainfrom
webproc-restart
Dec 4, 2026
Merged

g0shed merged 4 commits into
mainfrom
webproc-restart

Conversation

@g0shed

@g0shed g0shed commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

The web process that draws mail keeps what pictures took after a page is gone. It settles at 500 to 600 MB after an hour of reading and never goes lower. Clearing the page, clearing WebKit's memory cache and waiting do not free it. Ending the process does, and a new one starts near 110 MB.

This ends the process when nothing it draws is on screen, so the memory comes back while the person is away.

The rule

  • The process counts the pages it has loaded since it started. Below 20 it is left alone: a fresh process holds about 110 MB, and ending a small one gains nothing. WebKit does not tell the app the process id, so the page count stands in for reading its size.
  • Once it passes 20, one timer looks every 150 seconds at whether any web view is on screen. A view is on screen when it is mapped and its window is visible, not suspended and not minimized. The composer's preview and separate message windows count, so a message open anywhere keeps the process.
  • Two looks in a row that find nothing on screen end the process, so it rests for 2.5 to 5 minutes first. That is long enough that a quick trip to another pane or window costs nothing, and short enough to free the memory during a break.
  • The timer stops after it ends the process and starts again at the next 20th page. Nothing runs while the app reads little.

The process is ended with terminate_web_process. WebKit reports it through the same signal as a lost process. The conversation view already handled that signal by forgetting what the page held. It now also draws the open conversation again when the page had finished parsing before the process went. A page that died while loading is not redrawn, so a crash on load cannot loop.

The 48 MB inline picture cache is unchanged.

Numbers

Same scripted session as the memory investigation: 100 conversations opened with the Down key, then a pause (3000 messages, Dovecot, headless). Web process PSS:

moment web process PSS
fresh process 102 MB
after 100 opens, 30 s idle 520 MB
unseen window, conversation open: flat for 3 minutes 520 MB
the same, after the restart (conversation drawn again) 216 MB
empty reading pane, 30 opens later: flat for 4.5 minutes 310 MB
the same, after the restart 0 MB (no process)
first conversation opened after that 224 MB

Without the change the process stays where it is: a run of the same session on the build with no restart, with the window in use and then idle for 5.5 minutes, sat at 565 MB the whole time (593 MB right after the opens). The unseen-window case was driven with a test hook that reports every view as unseen. Xvfb has no window manager, so the real minimized and hidden checks were not run.

Time from load_html to the page's finished event, 132 loads in one session: median 52 ms, mean 67 ms. The first load in a fresh process took about 300 ms (303 and 312 ms), and the conversation drawn again after a restart took 312 ms. The person sees the conversation again at its top, as for any fresh open. I read screenshots of both cases (conversation open in the unseen window, and the first conversation after the empty pane) in dark mode; each shows the message normally, with no crash page.

Checks

  • Unit tests for the "end now?" decision: it waits for two quiet looks, a page on screen resets the count, a small process is left alone, and the count starts again after an end.
  • cargo clippy --all-targets -- -D warnings is clean.
  • Not run: macOS and Windows, which use their own web views and are unchanged. Minimized detection (the window's toplevel state) is untested on a real desktop.

… minutes

The process keeps what pictures took after the page is gone, and only ending it returns that memory. A conversation open in an unseen pane or window is drawn again at once.
@g0shed
g0shed merged commit 6b72064 into main Dec 4, 2026
23 checks passed
@g0shed
g0shed deleted the webproc-restart branch December 4, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant