Skip to content

perf(server): read a run's statements a page at a time from a cursor - #1737

Open
kvlonge wants to merge 2 commits into
mainfrom
perf/statement-list-read
Open

kvlonge wants to merge 2 commits into
mainfrom
perf/statement-list-read

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Why

A run page re-read every statement of every job run on each change, and the server summarised the whole run each time. A run past 5,000 statements listed only its first 5,000.

Changes

  • The statements read takes a cursor (after) and each record carries the next one. A read touches only the events stored after it, through two partial indexes on recall_events (migration 0014, and in indexes.sql).
  • Each request is authorized on its own. Requests for the same page share one read, which runs in a task of its own; a request waits out a read already under way, whose snapshot may predate it, and shares the next. The entry goes however the read ends. A scoped fensu exception covers the map, like audit_repeats.
  • The run page keeps each run's statements by ID, reads on until a page is not full, and numbers them by start. The "only the first 5,000" notice is gone.
  • A live read waits at least as long as its last read took before asking again, and a new wait replaces a pending one.

No DuckShop case: this is a server read and the page's polling, not a project shape, data value or lifecycle sequence.

Verification

Rows read, from EXPLAIN ANALYZE on PostgreSQL, for a 10,000-statement run beside another of 10,000:

  • main: 80,020 rows on every poll, listing the first 5,000 statements;
  • this branch: 35,051 rows for the first page, 76 for a poll with 5 new statements.

A guard holds 36,000 rows, 100 rows and 4 store statements per read. Each new test fails without its fix:

  • cursor paging on SQLite and PostgreSQL;
  • a request arriving while an older read holds its snapshot sees what committed since;
  • Playwright: reading past a full page, and back-off after a slow answer;
  • real server: one-at-a-time paging matches a whole read, and the page lists every statement.

Also: targeted cargo tests, clippy -D warnings, fensu, svelte-check, vitest, and the Playwright layout and real suites.

The run page re-read every statement of every job run on each change, and the
server summarised the whole run each time. A run's statement list is now read
from a recall_events.storage_id cursor: each read touches only the events
stored after it, through two new partial indexes, and identical concurrent
reads share one read. The page follows each run's statements like its events,
reads on until a page is not full, and waits at least as long as the last read
took before asking again.
@kvlonge
kvlonge enabled auto-merge November 30, 2026 17:52

This branch has not been deployed

No deployments
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