Skip to content

perf(storage): stop idle and repeated writes, and the caret timer with no drawn caret - #4435

Merged
datlechin merged 10 commits into
mainfrom
perf/writes-idle
Nov 23, 2026
Merged

datlechin merged 10 commits into
mainfrom
perf/writes-idle

Conversation

@datlechin

@datlechin datlechin commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Perf audit 2026-11-22, findings 19 and 20 (writes-idle lane).

  • Caret timer (WI12): CursorTimer runs only while a drawn caret is registered. From macOS 14 the caret is NSTextInsertionIndicator, which blinks itself, so the timer fired twice a second for nothing, also behind a Server Dashboard tab.
  • Table load history (WI1, D28 drop): TableLoadHistoryStore is gone. At its cap it rewrote 4.8 MB per table load. TABLEPRO_TABLE_LOAD_TRACE=1 prints one tableload <json> line per load to stderr, which apple/scripts/benchmark/app-paths/benchmark.py reads. The file older builds kept is removed after launch.
  • Periodic tab save (WI11): the 30 s save returns before encoding and hashing when the state with queries emptied has the same digest, every query is literally equal and the files are still there. Queries compare as NSString: edited text is the editor's NSTextStorage string, bridged with no contiguous UTF-8, and a walk of its utf8 view cost about 100 ms per 2 MB on every tick. Sleep tolerance 10 s.
  • Last session (WI4): LastSession.json and LastOpenConnections.json are left alone when the session is unchanged and both files exist. They were rewritten on every app switch.
  • Tips (WI3): no tip event is donated once no rule counts it. Find Past Queries stops at 10 runs; windowed tips stop once invalidated.
  • Query history (WI2a, WI2b): the two fingerprint_hash indexes nothing reads are dropped; user_version is written only when it differs; history_fts is rebuilt once with columnsize=0 and no prefix indexes, in one transaction, keeping the old index if the rebuild fails.
  • View state (WI6): deleting a connection also removes its tree expansion, Open Quickly frecency and split view autosave records. Connections opened from a file or a link go in TransientConnectionLedger, and their view state is purged after launch once no session and no window can reach them.

Before and after

Mac mini (12 cores), Release arm64. Before: origin/main 9d0d481. After: this branch at 61a9e50, before the dashboard cut and the WI6 fix, neither of which any row below exercises. cpu-idle --quick (60 s window), 3 before and 2 after runs in the order B B A A B; disk-io session (20 pages, 15 query runs, 10 app switches) and seeded (table load history and column layouts at their caps), one run each. Load is load1 at the start; the Mac was shared, load 3 to 530.

Item Metric Before After
WI11 save-large-bg (41 tabs, 10 MB of SQL), M instructions/min 487, 523, 402 18, 15
WI11 save-small-bg (reference: 41 short tabs), M instructions/min 53, 25, 24 21, 13
WI11 compare a 2 MB editor-text query with itself (probe) 99 to 134 ms (utf8 walk, load 258) 0.00 ms
WI12 query-fg interrupt wakeups/s 2.37, 2.37, 2.40 0.38, 0.42
WI1 table load history written per page, at the cap (seeded) 4,687 KB 0
WI1 bytes written per page, seeded (median) 4,956 KB 56 KB
WI1 table load history rewritten at launch, seeded 9.6 MB 0 (old file removed)
WI1 table load history per page (session) 0.5 KB 0 (no file)
WI2 history WAL per page 52.3 KB 36.8 KB
WI2 history WAL per query run 56.1 KB 36.7 KB
WI3 runs that write the TipKit WAL, of 15 1 to 15 1 to 10
WI3 bytes per query run, runs 11 to 15 120 KB 37.5 KB
WI4 session file replaces, 10 app switches 20 0

Tests changed on purpose

  • TableLoadHistoryStoreTests deleted with the store.
  • TableLoadPerformanceRecordTests: the two stored-format tests (older line decodes, previous stable reads this line) replaced by a mapping test.
  • TableLoadTracerSinkTests: the shared-tracer history file test replaced by no-sink, stderr line and retired file tests.

New: CursorTimerTests (10), TabDiskUnchangedSaveTests (+7), LastOpenConnectionsStorageTests (+4), FeatureTipsTests (+4), QueryHistorySearchIndexTests (5), TransientConnectionLedgerTests (10).

Deliberately not fixed here

  • WI9 (D15), PostgreSQL dashboard in two statements and the size once a minute, and WI10 (D17), dashboard reads off the user's session: cut under the review rule. Codex kept finding new defects in the review fixes: a read on the session driver (no database chosen) moved the transaction revision and voided an open Commit or Rollback confirmation; a pooled Cancel or Terminate can queue behind other work on the same pool entry; the kept size compared database names with String ==. WI10 needs a control connection Cancel and Terminate never share; WI9's kept size needs a byte-exact database key (CatalogName.same). With a dashboard open on this Mac: 86 PostgreSQL statements and 1,123 M instructions a minute before; the build with WI9 and WI10 read 27 statements and 909 M instructions.
  • WI8, one dashboard board per refresh: gate is a 60 s dashboard-fg profile, after WI9.
  • WI5, column layouts off the main thread: gate is a missed frame at the resize flush, not measured. Gate is quiet pass 2.
  • WI13, an answered statement as a connection check: needs the server log check on On demand first, and touches DatabaseManager+ScopedDriver.swift, which the connections lane changes.
  • WI14, wake a waiting row producer: one change with finding 16 in PluginStreamAbort and PluginRowSpill, after perf(export): MongoDB export documents, Parquet limits and unmeasured items left from #4434 #4444's M2 and EX5.
  • WI7, one-time sweep of unreachable view state: D18 asks for a key count on a Mac without debug builds; none was counted.
  • WI1 kept as a fixed store: D28 chose drop.

Test plan

  • verify.sh test, 27 suites (the changed ones plus tab persistence, query history, table load trace and dashboard): 282 passed, 0 failed (TableProTests 260, TableProTextEngineTests 22).
  • verify.sh lint on the changed Swift files: 0 violations.
  • WI11 probe: NSTextStorage(string:).string has no contiguous UTF-8, ASCII or not, before and after a typed character; String(contentsOf:encoding:) and JSON-decoded queries do.
  • Codex: adversarial on the WI11 change, clean. Review then found the dashboard refresh moving the transaction revision; the fix drew two more (pooled Cancel queued behind pool work, size cache identity), so WI9 and WI10 were cut. Review of the cut found the WI6 sweep purging an id a window still hosts after a failed connect, fixed. Final review clean.

Docs: TableProApp/docs#274.

Caret timer only for a drawn caret, no table load history file, unchanged
last session and tab state left alone, tip donations only while counted,
a slimmer query history schema, two dashboard statements a refresh off the
user's session, and view state removed with the connection that wrote it.
…ail the metrics panel when the server answered nothing
@datlechin
datlechin marked this pull request as ready for review November 23, 2026 10:57
… main

Codex kept finding new defects in the review fixes (transaction revision on server scope, pooled Cancel queued behind pool work, size cache identity). WI9 and WI10 move to the follow-up.
@datlechin datlechin changed the title perf(storage): stop idle and repeated writes, and read the PostgreSQL dashboard in two statements perf(storage): stop idle and repeated writes, and the caret timer with no drawn caret Nov 23, 2026
@datlechin
datlechin enabled auto-merge (squash) November 23, 2026 13:43
# Conflicts:
#	apple/TablePro/Core/Storage/ConnectionLocalState.swift
@datlechin
datlechin merged commit aaa1277 into main Nov 23, 2026
20 of 22 checks passed
@datlechin
datlechin deleted the perf/writes-idle 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