Skip to content

Keep the Log's unchanged rows between renders - #40

Merged
simonhamp merged 2 commits into
mainfrom
perf/log-render
Oct 20, 2026
Merged

simonhamp merged 2 commits into
mainfrom
perf/log-render

Conversation

@simonhamp

Copy link
Copy Markdown
Member

Every render of the Log rebuilt the whole list in Blade, serialised it and published it, so each page you loaded made every later render slower. On Simon's iPhone 16 Pro (Release, OPcache PHP) a page-1 render was 50-90 ms of PHP, and a few pages in it was 500-935 ms. Polls, async completions, taps and load more all paid that.

This keeps the rows between renders. RowCache holds each commit row and thread reply the Log drew last frame, hashed against the partial's data and everything else the row shows (RowInputs). A row whose hash hasn't changed is attached again instead of going through Blade. CachedRow wraps it and sends the row's own node in its place, so the frame is byte for byte what it was, and it keeps that node too, so toArray skips the row as well while it stays under the same keyed list.

It only uses EDGE's public pieces (NativeElementCollector::capture() and attachElement(), plus an Element subclass), so it needs nothing new from mobile-air.

Measured on Simon's iPhone 16 Pro, Release build with the OPcache PHP, scrolling the Following log by hand. Same build, cache switched off and on (the switch was a bench-only hook, not in this PR). Numbers are PHP time per render from EDGE's PERF lines, render + toArray + publish.

commits loaded without the cache with it
40 117 ms 82 ms
100 209 ms 65 ms
200 443 ms 77 ms
320 886 ms (stopped at 220)

The rows with the cache are load-more renders, which build the 20 new rows. A quiet 30s poll at 220 commits now costs 93, 61 and 32 ms for its three renders, where each one was at least 443 ms before. toArray on a frame where nothing changed went from about 100 ms to 1-3 ms at 200 commits.

Without the cache PHP stopped answering at 360 commits (looks like it runs out of memory and never recovers). That's for a separate change. With the cache the frame is the same size, so it doesn't fix that.

Locally, with 20 made-up commits a page on PHP 8.4 with OPcache on a Mac,: at 8 pages a render went from about 140 ms + 47 ms toArray to 8 ms + 1 ms.

What to watch for:

  • RowInputs has to cover everything a row partial reads from the screen, the clock or the device. Today that's the viewer, pastéis mode, stashed drafts, unfolded and opened commits, relative times, poll status, and which avatars and images are already downloaded. A partial that starts reading something new needs adding there, or its row keeps showing the old thing. The first test in LogRowCacheTest walks through each of those changes and checks the kept frame against one built from scratch; taking any of them out of RowInputs makes it fail, except the opened-thread flag, which threadBelow happens to cover in that fixture.
  • Only the Log uses it. Profile, Saved and the commit page still build every row, since they draw feed without a $rowCache.
  • What's left grows slowly with the list: hashing each row's inputs, the C publish walking every node, and the native diff. None of that is Blade.

Other options I looked at:

  • Capping how many commits the Log keeps. Rows above the screen would go, the list would jump, and scrolling back up would need a "load newer". Each render would still cost the cap times the per-row price.
  • EDGE list virtualization. NPHP_FLAG_VIRTUALIZE is only a reserved bit in php-bin-mobile, nothing reads it. mobile-ui's <native:virtual-list> draws fixed-height grey boxes outside its window and has no pull to refresh, end-reached or variable row heights.
  • REUSE markers instead of $forceFullFrames. Blade still renders every row and toArray still hashes every node, so it would only save the publish, about 3% of the time.
  • Skipping a publish when nothing changed. The C extension already compares each frame with the last and skips identical ones. The cost is all in PHP before that.

🤖 Generated with Claude Code

simonhamp and others added 2 commits October 20, 2026 14:31
Every render of the Log built, serialised and published the whole list, so
each page loaded made every later render slower. On an iPhone 16 Pro with
OPcache a page-1 render took 50-90ms of PHP, and a few pages in it took
500-935ms, for every poll, event and load more.

RowCache keeps each commit row and thread reply it drew last frame, hashed
against its partial's data and the other things it shows (RowInputs: the
viewer, pasteis mode, stashed drafts, unfolded and opened commits, relative
times, poll status and which images are on the device). A row whose hash is
unchanged is attached again instead of going through Blade. CachedRow sends
its row's node in its place and keeps that node too, so toArray skips it as
well while the row stays under the same keyed parent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Serializing every commit each frame was most of what a kept row still
cost. The data objects are readonly, so RowCache keeps each one's hash in
a WeakMap for as long as the object lives.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonhamp
simonhamp merged commit fbf12a3 into main Oct 20, 2026
1 check passed
@simonhamp
simonhamp deleted the perf/log-render branch October 20, 2026 16:04
simonhamp added a commit that referenced this pull request Oct 21, 2026
…49)

The Log keeps the rows it drew last frame (RowCache, from #40), so a
render only builds the rows that changed. Profiles, Starred and a commit's
replies drew every row afresh on every render, so they got slower with
every page they loaded, as the Log did.

A profile keeps a cache per tab, Starred keeps one, and a thread keeps its
replies. The commits above a thread's replies still build every time: they
read what the screen shows of the thread, which the cache doesn't hash.

The tab you're not on in a profile now previews three commits instead of
five, as the Log's pages beside yours do.

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