Skip to content

Speed up the timeline's frames around its kept rows, and say why they aren't #[Memo] - #187

Draft
simonhamp wants to merge 7 commits into
integration/timeline-memo-basefrom
perf/memo-timeline-rows
Draft

simonhamp wants to merge 7 commits into
integration/timeline-memo-basefrom
perf/memo-timeline-rows

Conversation

@simonhamp

Copy link
Copy Markdown
Member

This PR's base is integration/timeline-memo-base: main with the open PRs #175, #176, #177, #178, #179, #180, #181, #182, #183 and #186 merged in, the combination Simon's phone runs. That keeps the diff to this work alone. It gets retargeted to main once those PRs land.

Why the rows aren't #[Memo] components

The question was whether the Log and profile rows use #[Memo] from mobile-air 4.8. They don't, and they shouldn't. Since #40 they go through App\Devnull\RowCache, which already does what Memo does and a bit more: it keeps each row's elements and the node it sent, against a hash of what the row shows, so an unchanged row costs one hash a frame.

I turned the feed's commit and reply rows into a #[Memo] child component on mobile-air 4.8.0 and timed both on the same data. Memo was slower on every step:

PHP per step, Mac RowCache #[Memo]
Log, star a commit 6.8 ms 10.7 ms
Log, open and close a sheet 11.5 ms 20.0 ms
Log, nothing changes, 60 commits 6.4 ms 18.8 ms
Log, pull to refresh, 60 commits 7.7 ms 23.6 ms
Profile, star a commit 7.2 ms 11.1 ms

Two reasons. The Log, profiles, Search and Starred send every frame in full ($forceFullFrames), and Memo's shortcut is a reuse marker that only works with subtree reuse on, so it walks and serialises every kept row again each frame. CachedRow skips that walk. And Memo compares a child's props every frame by serialising any object among them, which here is the Commit, where RowCache hashes each readonly commit once. So the rows stay where they are and this PR goes after the rest of each frame. The prototype isn't in this PR.

What changed

  • A row asked the account for your pastéis again whenever the screen passed null, which it does with pastéis mode off. That's a SQLite query on a phone, so a frame on the Log ran one per row. Null now counts as an answer, for $viewer too.
  • The skeleton rows, the loading row at the end of a list, the root commit row, day markers, the last-visit marker and a profile's pinned commit were built afresh every frame. They now go through the list's RowCache with its commits, on the Log, profiles, organizations, Starred and Search. On the Log that was five rows on every frame.
  • The log beside yours read its kept answer and parsed its first commits again every frame. It's now kept with a hash of what it came from and only made again when that changes.
  • A row is kept against its own drafts and its own Show more, not the whole list, so the first letter of a quote or reply no longer builds every row on the screen.
  • A commit page's commit, what it replies to, its series and the related commits now go through the page's RowCache like its replies. Typing a reply used to build all of them on every frame. The focused commit is also kept against whether its replies are open, its reply count and your timezone.
  • Found by the new kept-row checks: a poll's Vote button wears your lane colour, which RowInputs didn't cover, so after changing your colour the Log kept the old one on that button.

Every frame is the same as before. The bench below records the tree each step ends on, and all 336 of them match the base branch's, node for node, so there's no visible change and the phone gets as much as before: about 204 KB a frame on a Log of 20 commits and 530 KB with 60, measured as the tree's JSON.

Numbers

Mac, PHP only (render plus toArray, median of 11 runs, same fixtures, cache in SQLite and kept answers in files as on a phone):

Step Before After
Log, first render, 20 commits 43.4 ms 40.7 ms
Log, a frame where nothing changes 7.1 ms 3.2 ms
Log, star a commit 8.8 ms 5.1 ms
Log, open a thread 16.0 ms 11.9 ms
Log, close it 8.7 ms 4.9 ms
Log, open and close the quote sheet 15.8 ms 8.4 ms
Log, next page goes in while scrolling 42.4 ms 34.5 ms
Log, next page at the end 40.9 ms 34.5 ms
Log, star with 60 commits 12.1 ms 6.1 ms
Log, nothing changes with 60 commits 10.2 ms 4.3 ms
Log, pull to refresh 11.1 ms 5.2 ms
Profile Commits, first render 37.8 ms 37.5 ms
Profile Commits, star a commit 9.5 ms 7.1 ms
Profile Commits, open a thread 17.3 ms 14.5 ms
Profile Commits, nothing changes 8.1 ms 5.3 ms
Profile Replies, switch to the tab 36.9 ms 36.8 ms
Profile Replies, star a reply 10.2 ms 8.0 ms
Organization, star a commit 7.9 ms 5.2 ms
Organization, nothing changes 7.0 ms 3.8 ms
Commit page, first letter of a reply 12.3 ms 5.2 ms
Commit page, next letter 6.4 ms 3.6 ms

On an iOS 27 simulator and an Android 15 emulator, a debug build of each side ran a scripted session against a fake API serving the same fixtures, one step every 1.5 s, timed from mobile-air's own PERF lines in edge-nav.log. This is the frame each step caused, render plus toArray, median of five runs:

Step iOS before iOS after Android before Android after
Log, every frame where nothing changed 12.3 ms 5.1 ms 8.9 ms 5.6 ms
Log, star a commit 15.3 ms 7.6 ms 8.2 ms 6.3 ms
Log, open a thread 30.9 ms 19.0 ms 17.7 ms 15.0 ms
Log, close it 29.5 ms 20.2 ms 11.9 ms 7.9 ms
Log, open the quote sheet 23.6 ms 17.6 ms 15.5 ms 14.4 ms
Log, next page goes in while scrolling 43.9 ms 38.3 ms 32.3 ms 31.0 ms
Log, star with 60 commits 15.7 ms 8.0 ms 10.8 ms 8.5 ms
Log, pull to refresh 15.0 ms 6.4 ms 11.3 ms 7.7 ms
Profile, every frame where nothing changed 11.9 ms 8.7 ms 7.9 ms 6.0 ms
Profile, star a commit 13.3 ms 7.9 ms 9.8 ms 7.6 ms
Profile, open a thread 21.8 ms 19.4 ms 14.1 ms 10.1 ms
Profile, switch to Replies 38.0 ms 28.9 ms 8.7 ms 9.0 ms
Profile, star on Replies 13.7 ms 11.1 ms 11.5 ms 7.1 ms

First renders barely move on either: building a row costs about the same as before (about 1 ms each on a Mac), and that's most of a first render.

The bench, the timing harness and the fake API aren't in this PR. They're attached to the board entry for this task, with how to run them.

What to watch for

RowInputs is the contract: anything a row partial reads from its screen has to be in it, or a kept row shows what it showed before. The tests in LogRowCacheTest and RowCacheScreensTest now change a star, the time, your timezone, your colour, your organizations, a draft, Show more and a thread's state, and check kept rows against rows built afresh. A partial that starts reading something new needs adding there too.

On the commit page, the commit it's about reads its replies' state and your timezone from the page, so those are in its inputs as well (commit-detail.blade.php). That test fails if they're taken out.

Not done here

  • The Log, profiles, Search, Starred, Notifications and Remotes send every frame in full because subtree reuse once referred to rows the phone never got and drew the Log blank. With reuse on, the bench sends about 0.1 KB for a frame where nothing changed instead of 204 to 530 KB. It would need the old bug re-tested on current mobile-air, and CachedRow would need to send reuse markers for kept rows, or a one-row change still sends every kept row in full.
  • A Log frame still runs about 14 cache queries and a profile frame about 21, mostly Account::user() asked again from several places. Remembering it for a frame would cut most of them, but background tasks read the same keys from another runtime, so it needs care.
  • A commit row is about 48 nodes and costs about 1 ms to build on a Mac, commit-actions and commit-row-content most of it. That's what first renders, next pages and opening threads pay for. Fewer nodes per row is the lever there.
  • For #[Memo] to help a list in mobile-air, a memoised child would need to keep its serialised node on full-frame screens, as CachedRow does, and compare object props without serialising them every frame.

Screenshots

Nothing a user sees changed: every frame matches the base branch's. Checked by hand on an iOS simulator and an Android emulator in light and dark: starring, opening and closing threads, the quote sheet, next pages, pull to refresh, a profile's tabs, and a commit page's replies and reply bar all update as before.

  • No visible change

🤖 Generated with Claude Code

simonhamp and others added 6 commits November 18, 2026 20:27
With pastéis mode off, the screen passes $pasteis as null, and both
RowInputs::for() and commit-actions treated null as "not given" and
asked the account again. That's a query on the phone, where the cache
is the app's SQLite database, so every row on the Log cost one on every
frame, kept or not: 24 queries a frame on a log of 20.

Null is now an answer. The account is only asked when the screen passed
nothing at all. The same goes for $viewer, which is null when you're
signed out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every frame built the rows around the commits afresh: the skeleton rows
of a log or tab with nothing loaded, the loading row at the end of a
list, the root commit row, the day markers and the last-visit marker,
and a profile's pinned commit. On the Log that was five skeleton and
loading rows on every frame, about a third of a frame where nothing
changed.

They now go through the list's RowCache like its commits, on the Log,
profiles, organizations, Starred and Search. Each is kept against what
it draws, so a loading row that stops pulsing when you swipe away is
built again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every frame read the answer kept for the log beside yours and made its
first commits afresh, with their bodies parsed again. New commits then
missed the timeline laid out for them last frame and the rows kept for
them, so each was hashed again too.

The preview is now kept with a hash of what it was made from, and only
made again when that changes, as it does when a star or a delete
reaches the kept answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A poll you can vote on draws its Vote button in your lane colour, which
the row reads from the screen. RowInputs didn't have it, so after you
changed your colour the Log kept the old one on that button until the
row changed for some other reason.

The kept-row test now also changes your colour and joins you to an
organization whose commit is showing, and checks the kept rows against
rows built afresh, as it did for stars, times and threads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RowInputs kept every row against the whole list of stashed drafts and
unfolded commits, though a row only shows its own: a dot on its Quote or
Reply button, and its body whole once you tapped Show more. Starting a
draft anywhere, as the first letter of a quote or a reply does, built
every row on the screen again.

Each row is now kept against its own drafts and its own unfolding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The commit a page is about, what it replies to, the rest of its series
and the related commits were built again on every frame. Typing a reply
draws a frame a few times a second, so each letter built every commit
above the reply bar.

They now go through the page's RowCache with its replies. The commit
the page is about is also kept against what it shows of its thread
(whether its replies are open, and how many) and your timezone, which
its time's label is in. The test changes each of those, and the time,
and checks the kept rows against rows built afresh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #178's HEAD@{last visit} band.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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