Skip to content

perf(window): release closed connection windows and keep startup work off the main thread - #4431

Merged
datlechin merged 10 commits into
mainfrom
perf/lifecycle
Nov 23, 2026
Merged

datlechin merged 10 commits into
mainfrom
perf/lifecycle

Conversation

@datlechin

@datlechin datlechin commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

  • A closed connection window is released (perf audit finding 3). The command actions' table binding captured the whole MainContentView, whose @State held those actions and the window. It now binds to WindowSidebarState. @State viewWindow is gone; readers use coordinator.contentWindow.
  • The pane closures and title bindings no longer capture ConnectionWorkspace strongly.
  • TabWindowController.windowWillClose tears each hosted workspace down one turn later, once the window is off screen. A workspace another window hosts by then is skipped.
  • MainContentCoordinator.teardown() runs once, so the schema provider hold is released once.
  • The close button asks about unsaved work and running work through windowShouldClose (D2). The button sends its own action, not performClose:, so EditorWindow.performClose never saw it. A second click while the question is up asks nothing more.
  • Option-click asks one Review Changes alert for every window holding work (D2): Review Changes…, Cancel, Discard Changes. Each window is checked again before its own question.
  • A window with no browse content (Agent mode while connecting) still asks before it stops a running agent reply.
  • Keychain reads for a driver open run off the main actor (DeferredSecretRead, finding 21a). Same reads, same answers, same log lines. Local only still reads this Mac's item first.
  • LegacyLicenseStore reads the set-aside digest and the payload from defaults before it touches the Keychain.
  • A hidden inspector no longer copies the selected rows on every selection change (21b). A reveal fills it once. The handlers still follow the tab, and they capture the coordinator weakly.
  • Stored agent sessions build their engine when something reads it (21e). Stop, release, delete and quit of an unopened session build none.
  • Deleting a connection deletes its agent sessions and their conversations, also on a remote delete (D21).
  • A removed session's engine forgets its transcript, so a cancelled tool round that finishes late cannot write it back. The conversation id is read after the cancel, so a transcript the cancel first saved is deleted too.
  • Closing the last window of a connection stops its agent sessions and keeps the transcript (D29).
Item Benchmark Before (9d0d481cf1) After (this branch, Release)
L1 memory --only windowcycles, 20 open + close cycles 47,335 KB per cycle, +879 MB 105 KB per cycle, +6.5 MB
L1 coordinators, workspaces, split views after 20 closes 20, 20, 20 0, 0, 0
L1 memory --only closecheck, coordinators after one close 1 0
L3 launch --only keychain, kc-connect Keychain calls on main (relaunch / first launch) 22 / 25 3 / 6
L3 store reads per relaunch with 3 driver opens 22 21 (the L4 read)
L4 kc-welcome store reads, license reads 4, 2 3, 1
L7 launch --only bbl, 500 stored sessions minus 6 connections: footprint +4.98 MB +0.59 MB
L7 same, instructions to first frame +558 M +49 M
L5 ui-responsiveness --scenarios selection, edit state configure hits per Cmd-A, inspector hidden 1 0
L5 Cmd-A on a 10,000-row page, inspector hidden: main CPU, process instructions (mean of 2) 62.6 ms, 877 M 27.8 ms, 246 M
L5 Cmd-A on a 1,000-row page, same 30.1 ms, 300 M 30.5 ms, 256 M
  • Counts and instructions barely move with load; n=1 per row except Keychain (n=2). Load average 5 to 25 during the runs.

Tests changed on purpose

  • None.

New tests

  • ConnectionWindowReleaseTests: a closed window lets go of its coordinator and actions and empties its panes (fails on main), two connections, teardown only after the window is ordered out, a workspace hosted elsewhere is kept, a removed workspace and an ended session release their coordinator, the schema provider hold is released once, the last window stops its agent sessions.
  • ConnectionWindowCloseQuestionTests: no work closes, staged work asks and Cancel keeps the window, an open cell edit lands first, a second click asks nothing, a window with no browse content asks about an agent reply, Option-click detection, one Review Changes alert per event, Discard closes all, Review stops at the first Cancel, a window closed meanwhile is skipped, one window gets its own question.
  • WindowCloseButtonUITests: a real click on the close button asks, Cancel keeps the edit, Don't Save closes.
  • HiddenInspectorEditStateTests, DriverOpenSecretReadTests, LegacyLicenseStoreTests, and new cases in AgentSessionRegistryTests and ConnectionLocalStatePurgeTests.

Deliberately not fixed here

  • L6 (Cloud SQL key files in their own folder, finding 21d) is cut and left for a follow-up. Two security review rounds found ways an older build run since the upgrade could leave a service account key in $TMPDIR that the one-time sweep never lists again. Main keeps listing $TMPDIR at every launch (in the background; 72 to 75 ms CPU at 24,983 entries on the audit Mac, 4,578 entries here) and at quit on the main thread.
  • The release test checks the coordinator, the actions and the panes, not the NSWindow: the unit test host keeps closed windows in an autorelease pool it never drains. The memory bench above counts the window's split view and workspace in the real app.
  • The plan's lldb ptr_refs check before the build was skipped: the bench counts settle the cause.
  • In an Option-click, a window with no browse content asks with its own sheet, not inside the Review Changes alert.
  • Pooled leases reusing the session's Keychain answers: belongs with finding 5.
  • Older conversations in a deleted connection's history list stay; D21 covers its sessions and their transcripts.
  • NULL display setting (21c): fixed on main by feat(settings): native macOS Settings sidebar with pushed pages and history #4413.

Docs: TableProApp/docs#272

@datlechin
datlechin marked this pull request as ready for review November 23, 2026 07:32
@datlechin
datlechin enabled auto-merge (squash) November 23, 2026 07:32
@datlechin
datlechin merged commit 2a3dc8c into main Nov 23, 2026
11 checks passed
@datlechin
datlechin deleted the perf/lifecycle branch November 27, 2026 16:38
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