Public: anyone can read this; the crew can change it.
The signed-in home and feed spend 240 to 260 ms on every warm load counting "new" items (0930c49ab) #13630
Check · Review · Land · Live done — Landed and live in production.
The new phase on /feed is now a kept read: warm loads skip the walk of the candidates. I could not measure it against production, so the under-10 ms target is not confirmed on the real forge. The new count tests, home-feed-budget and tsc pass.
shipped production is serving it deploy 8e1361f
The new phase on /feed is now a kept read: warm loads skip the walk of the candidates. I could not measure it against production, so the under-10 ms target is not confirmed on the real forge. The new count tests, home-feed-budget and tsc pass. I did not run the broader suites, because scripts/fast.ts named 1,911 test files and that run timed out in the sandbox.
What was wrong. newSince walked every candidate the feed holds for the viewer. Those candidates sit in a cache stamped by the forge's write clock, and that clock moves on every write, not only on events. On a forge that writes all day the cache is cold on most loads, so the count recomputed the whole candidate set. My 5,000-event fixture only costs 10 to 30 ms for that walk, so I could not reproduce production's 250 ms. The cause is my reading of the code, not something I measured.
What changed (src/feed/last_seen.ts):
- Kept count. The count is memoised per viewer, mark, mutes, dismissals and chips.
- Clock. The stamp is the event log's own clock,
SELECT MAX(seq) FROM event, an index read. The count is re-read when an event lands, when a mute, dismissal, chip or mark changes, and at the latest 30 s later. The 30 s covers changes no event reports, such as an access grant. - Cost. The first load after an event still pays the walk once.
Not done:
- Index or range count. The count is "what the feed would show", which depends on folding, mutes, chips and access, so it cannot be a plain range query. I chose a kept count over an index-backed rewrite that could drift from the feed. The exactness tests (
feed-new-count,feed-new-count-exact) pass unchanged. - Query plan. There is no before and after plan to show. The only new query is the clock read, and the test asserts it does not scan.
keep.ts. The count does not joinsrc/flow/keep.ts.- Cold cost. I did not reduce the cold walk itself.
Why the budget test passed. test/pages-budget.test.ts judges counted work (SQL statements and git processes) and prints the clock without judging it. The count added a few statements, not a pattern. home-feed-budget times /feed with the forge idle, so the candidate cache stayed warm and hid the cost. I did not change pages-budget.
New test. test/feed-new-phase.test.ts seeds 5,000 events, keeps writing non-event rows, and checks three things:
- The clock query is an index read.
- A non-event write causes no walk of the candidates, and an event causes exactly one.
- A warm
/feedhas anewphase under 10 ms.
The no-walk assertion fails if the fix is stashed. The 10 ms timing assertion passed even without the fix, because the fixture is lighter than production.
To check on the preview, load /feed signed in a few times and read Server-Timing: new should stay under 10 ms between loads while writes continue.
🤖 Generated with Claude Code
The gate failed because no commit message in the pull had a Try: line. I added an empty commit that has one and pushed it. I didn't re-run the check or the tests, since the commit changes no code.
Try: open /feed on the preview while signed in and read the new count. Open /feed again, and the count should stay the same until something new is posted.
The code change from cf46dc23b is as before. It keeps the feed's new count under the event log's clock, so a warm /feed no longer walks the candidates on every write.
The new count is now a kept read stamped by the event log clock (an index read), keyed by viewer, mark, mutes, dismissals and chips. It is small, has no UI or door change, and adds no dependency. The no-walk test (misses unchanged after a non-event write, +1 after an event) would fail without the fix. I read the diff and the tests only. I did not exercise the signed-in preview, since I have no session there. Two things to do next: 1) The 10 ms timing assertion passes without the fix, as you said, so it guards nothing. Drop it or tighten the fixture until it fails unfixed. 2) Access revocation (a grant removed, a repo made private) is only seen after up to 30 s, so a viewer can briefly count posts they can no longer see. Bump the stamp on access changes, or say in docs/CACHING.md that this is accepted. Also sort the import so ../kernel/stamped.ts follows ../core/*.
The
newphase on/feedis now a kept read: warm loads skip the walk of the candidates. I could not measure it against production, so the under-10 ms target is not confirmed on the real forge. The new count tests,home-feed-budgetandtscpass. I did not run the broader suites, becausescripts/fast.tsnamed 1,911 test files and that run timed out in the sandbox.What was wrong.
newSincewalked every candidate the feed holds for the viewer. Those candidates sit in a cache stamped by the forge's write clock, and that clock moves on every write, not only on events. On a forge that writes all day the cache is cold on most loads, so the count recomputed the whole candidate set. My 5,000-event fixture only costs 10 to 30 ms for that walk, so I could not reproduce production's 250 ms. The cause is my reading of the code, not something I measured.What changed (
src/feed/last_seen.ts):SELECT MAX(seq) FROM event, an index read. The count is re-read when an event lands, when a mute, dismissal, chip or mark changes, and at the latest 30 s later. The 30 s covers changes no event reports, such as an access grant.Not done:
feed-new-count,feed-new-count-exact) pass unchanged.keep.ts. The count does not joinsrc/flow/keep.ts.Why the budget test passed.
test/pages-budget.test.tsjudges counted work (SQL statements and git processes) and prints the clock without judging it. The count added a few statements, not a pattern.home-feed-budgettimes/feedwith the forge idle, so the candidate cache stayed warm and hid the cost. I did not changepages-budget.New test.
test/feed-new-phase.test.tsseeds 5,000 events, keeps writing non-event rows, and checks three things:/feedhas anewphase under 10 ms.The no-walk assertion fails if the fix is stashed. The 10 ms timing assertion passed even without the fix, because the fixture is lighter than production.
To check on the preview, load
/feedsigned in a few times and readServer-Timing:newshould stay under 10 ms between loads while writes continue.🤖 Generated with Claude Code
Closes #13629