Skip to content

perf(idle): save tabs only after a change and let the app nap with a tunnel open - #4597

Merged
datlechin merged 4 commits into
mainfrom
perf/idle-saves-and-app-nap
Nov 27, 2026
Merged

datlechin merged 4 commits into
mainfrom
perf/idle-saves-and-app-nap

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • Tab saves follow changes. QueryTabManager.persistenceGeneration moves on every write a tab save reads: the tabs setter, the selection, the editor's fast text path, the caret (cursorPositions) and the grid selection (QueryTabGridStateStore.selectionSnapshot). Each move drives the existing 1 s debounced save, which replaces the per-window 30 s loop.
  • An unchanged save returns early. TabPersistenceCoordinator.saveAggregatedIfChanged() compares a fingerprint (every hosting window's generation plus the browsed database and schema) with the one the last save went out with, and returns before aggregatedTabs, toPersistedTab, the JSON encode, the hash and the file checks. Quit, window close and disconnect keep their synchronous saves, which always run.
  • App Nap. The SOCKS, Cloudflare, Cloud SQL and tunnel command managers no longer hold beginActivity(.userInitiatedAllowingIdleSystemSleep) for the life of a tunnel. The last three relay in a child process; the SOCKS relay runs on NWConnection receive callbacks, and socket readiness wakes a napped process, which is what perf(ssh): relay each session's channels from one event-driven reader and drop the App Nap hold #4248 measured for SSH.

Test plan

  • TabPersistenceGenerationTests (new): each saved input, written through its normal path, moves the generation, a same-value write does not, and each write reaches the owner's change-driven save.
  • Not built locally: the shared Mac ran out of disk during this run, so CI's Unit plan is the first compile and run of this branch.
  • Before: about 2 passes per connection per minute, each building every tab on the main actor while idle. After: none after the last change.
  • Not measured here: powermetrics idle wakeups and the napped relay latency need a live SOCKS and Cloudflare tunnel; listed on perf(idle): save tabs only after a change and let the app nap with a tunnel open #4558.

Closes #4558

…tunnel open

Each window ran its own 30-second loop that rebuilt, encoded and hashed every tab
only to find nothing changed. A persistence generation now moves on every write a
tab save reads, drives the existing debounced save, and lets a save return before
building anything when it did not move. The SOCKS, Cloudflare, Cloud SQL and tunnel
command managers no longer hold an App Nap activity for the life of a tunnel.
@datlechin
datlechin enabled auto-merge (squash) November 26, 2026 01:51
@datlechin
datlechin merged commit 32b4099 into main Nov 27, 2026
11 checks passed
@datlechin
datlechin deleted the perf/idle-saves-and-app-nap branch November 27, 2026 16:37
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.

perf(idle): save tabs only after a change and let the app nap with a tunnel open

1 participant