Repository navigation
Description
Problem
Nothing bounds the memory of results across a session. Every background tab keeps its rows, every result of a multi-statement run is kept, and pinned results stay, in every window and connection, until the user closes or re-runs them. All of it is dirty anonymous memory, which macOS can only compress or swap.
One 1M x 20 result (SELECT * FROM trips_1m, Execute Without Limit) raised phys_footprint by about 690 MB on PostgreSQL (573 to 1,262 MB) and about 600 MB on MySQL (257 to 856 MB). #4521 makes each result much smaller, but the number of results held still has no bound.
Cause
TabSessionRegistryholds each tab'sTableRowsuntil the tab closes, reloads or replaces them (apple/TablePro/Models/Query/TabSessionRegistry.swift:9-10,:52-58,:76-82).- A tab switch only drops formatted text, as the code says: "The only memory a tab switch releases: formatted text, rebuilt per drawn cell. Rows stay until the user replaces them." (
apple/TablePro/Views/Main/Extensions/MainContentCoordinator+GridModels.swift:280-289). - Each
ResultSetholds its owntableRows(apple/TablePro/Models/Query/ResultSet.swift:30). The active result shares its buffer with the session (apple/TablePro/Views/Main/Extensions/MainContentCoordinator+TableRowsMutation.swift:149-155), so pinned and non-active results are the extra copies. resultSetsKeptPerRundefaults to 0, which keeps every result a run returns (apple/TablePro/Models/Settings/AppSettings.swift:116-117,:136), up to 100 per run (apple/TablePro/Models/Query/QueryBatchResult.swift:29).- The Mac app has no memory-pressure handling. fix(tabs): keep a table tab's rows until you reload it #3848 (fcc7073) removed
MemoryPressureAdvisorand the evict-and-refetch schedulers, because a refetch changed what a clean tab showed.TableTabRowRetentionTestspins that contract: a tab shows the rows it last read. A comment still names a "memory-pressure monitor" that no longer exists (apple/TablePro/Core/Services/Infrastructure/LaunchEnvironment.swift:52).
Change
This builds on #4521's store and does not change it. A2 owns the columnar store, the window reads and teardown. This issue owns which held results stay resident.
- One budget for the app, in bytes, derived from physical memory the way
GridDisplayCacheBudgetpicks its tier. It counts the bytes each core store holds.ResultStorehas no such read today (core/crates/ffi/src/results/store.rs), so add one, with the same measure ADR 0020 uses for a run's byte limit (core/docs/decisions/0020-a-run-keeps-a-byte-limit-of-rows.md). - What counts: every result not on screen. That is background tabs' buffers, non-active results of a multi-statement run, and pinned results, across all windows and connections. A visible result never counts against eviction. Staged edits stay in memory in the store's overlay and never spill.
- Over the budget, least recently shown first:
- Spill. The core store writes its full chunks to a file in the caches directory and maps them back read-only. Those pages are clean and file-backed, so the kernel can drop and re-read them without the app walking any cache. A tab that comes back shows the same rows with no query sent, which keeps the fix(tabs): keep a table tab's rows until you reload it #3848 contract.
- Drop and reload applies only to a table tab's page, never to a query result, since running a statement again can write or return other rows. Reloading on return changes what a clean tab shows, which fix(tabs): keep a table tab's rows until you reload it #3848 removed on purpose. It needs a product decision before it ships. Until then, spill is the only path.
- No new limit on rows or on kept results (D3). A single result larger than the budget stays whole while it is shown.
- Fix the stale
LaunchEnvironmentcomment.
Measure
- Script: 50 tabs over 10 connections, 5 of them 1M-row query results with no row limit, one multi-statement run that keeps 20 results, and 3 pinned results. Record
footprint(dirty plus compressed) andvmmap --summaryafter each step and after an hour idle. Before: dirty footprint grows with every tab. After: dirty footprint stays near the visible tabs plus the budget, and spilled chunks show as clean file-backed regions invmmap. - Switching back to a spilled tab: identical rows, no statement in the server's statement log,
TableTabRowRetentionTestspassing, and the switch time fromTabSwitchTracereported. - A tab with staged edits keeps them through any amount of spilling of other tabs.
Part of the performance plan; depends on #4521.
Activity