TUI: watermark-based refresh on quiet inbox #3

Open
opened 2026-05-07 09:53:09 +02:00 by arne · 0 comments
Owner

Problem

The TUI re-runs store.Peers() and store.MessagesWithPeer() every 250ms, regardless of whether anything changed. On a quiet inbox this is wasteful (two SQLite queries per tick × the TUI's lifetime). With WAL it doesn't break anything, but it's churn for nothing.

Proposal

Track the highest message rowid the TUI has observed. On each tick:

  1. Read MAX(id) FROM messages (one cheap query against the primary key).
  2. If unchanged from last tick, skip the rest.
  3. If changed, do the full refresh and update the watermark.

Equivalent shapes (e.g. a small in-process pubsub from the daemon side, or SQLite's update_hook) are also fine, but the watermark is the simplest correct thing.

Acceptance criteria

  • Quiet-inbox tick path runs at most one indexed SELECT MAX(id) query
  • Refresh on actual change is unchanged in behavior
  • Restart of the TUI re-syncs (no stale watermark across runs)

Context

Surfaced in the v1.0.0 self-review. Not a v1 blocker; perf-only.

## Problem The TUI re-runs `store.Peers()` and `store.MessagesWithPeer()` every 250ms, regardless of whether anything changed. On a quiet inbox this is wasteful (two SQLite queries per tick × the TUI's lifetime). With WAL it doesn't break anything, but it's churn for nothing. ## Proposal Track the highest message rowid the TUI has observed. On each tick: 1. Read `MAX(id) FROM messages` (one cheap query against the primary key). 2. If unchanged from last tick, skip the rest. 3. If changed, do the full refresh and update the watermark. Equivalent shapes (e.g. a small in-process pubsub from the daemon side, or SQLite's `update_hook`) are also fine, but the watermark is the simplest correct thing. ## Acceptance criteria - [ ] Quiet-inbox tick path runs at most one indexed `SELECT MAX(id)` query - [ ] Refresh on actual change is unchanged in behavior - [ ] Restart of the TUI re-syncs (no stale watermark across runs) ## Context Surfaced in the v1.0.0 self-review. Not a v1 blocker; perf-only.
Sign in to join this conversation.
No labels
needs-triage
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
arne/msg#3
No description provided.