Skip to content

Hold Log frames while the list is scrolling - #93

Merged
simonhamp merged 1 commit into
mainfrom
perf/log-scroll-phase
Oct 26, 2026
Merged

simonhamp merged 1 commit into
mainfrom
perf/log-scroll-phase

Conversation

@simonhamp

@simonhamp simonhamp commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

The Log sends the phone fewer frames while you scroll. Each frame that lands mid-fling costs the iPhone's main thread a pass over the list. The b4 to b8 traces put most hitches just after one, and until now nearly every visible-range report (every 20 rows) sent one, because each report moved the rows drawn.

While the list is moving, a report now leaves the frame as it was unless one of these is true:

  • the screen is within 50 rows of the edge of the rows drawn (RowWindow::Reserve). They reach 150 rows ahead, so that's about every 100 rows instead of every 20.
  • the end of the list is within 40 rows and the next page is already here (NextPageWithin, as before).

Those renders, and the 30 second poll, keep the time of the frame before them, so a "4m" turning "5m" doesn't change the frame either. php-bin-mobile already drops a frame identical to the last one, so nothing reaches the phone.

When the list comes to rest it calls scrollEnded() through mobile-ui's new on-scroll-end (NativePHP/mobile-ui#177). The rows are drawn around the screen again and the times catch up. A frame then can't make the scrolling stutter.

Once you've scrolled, pages also go in while the list is at rest, one after another as they land, until 80 timeline rows sit below the screen (NextPageAtRestWithin). That gives the next fling room before it needs a page mid-scroll. Opening the log still fetches only one page ahead.

On Simon's iPhone 16 Pro, release builds, 75 seconds each of flinging down Following with 2 to 3 second pauses. Before is main (9ea6362) with mobile-ui main, after is this branch with mobile-ui#177, both on the same mobile-air shell. The screen counts as moving when the app drew frames in the 300 ms before.

before after
Seconds scrolling 27 32
Log frames sent while moving 8 1
Log frames sent at rest 2 19
Hitches while moving 18 (408 ms) 3 (29 ms)
of those, 33 ms or more 4 0
Hitches at rest 7 (138 ms) 12 (388 ms)
of those, 33 ms or more 2 6

Before, 13 hitches ended within 0.35 s of a frame sent mid-scroll. After, none did. The slow frames now land once the list has stopped, where a late frame holds up an update for a few frames instead of interrupting the motion. It's one hand-scrolled run each, so read the at-rest numbers loosely.

What to watch for:

  • This needs Tell a list's screen when a scroll comes to rest mobile-ui#177. Until it's merged and the lock is bumped, the one test asserting the on_scroll_end prop fails, and on a phone the Log would never hear that the list stopped. It still works then, with the rows drawn moving every 100 rows or so and pages going in near the end.
  • A visible-range report that isn't from a scroll (rows inserted above the screen) marks the list as moving until the next scroll ends. Until then the poll keeps its time and nothing is topped up. I haven't found a case where that happens on the Log, since the pill and pull to refresh replace the list.
  • 80 rows at rest means up to three more page fetches after a scroll stops, each with its images. The number is a guess and easy to change.
  • The at-rest frames are the catch-up and the topped-up pages. If one landing just as you start the next fling turns out to be noticeable, lowering NextPageAtRestWithin sends fewer.

Tests: RowWindowTest covers the rows drawn staying put until the screen nears either edge, and never nearing an edge that's the end of the feed or the top rows. LogPageFramesTest checks the frame stays byte-identical mid-scroll, poll included, with the times catching up at rest. LogPrefetchTest covers topping up at rest, holding pages that land mid-scroll, and opening the log fetching one page ahead. Five existing tests now draw around the screen, or stop the list, before checking the rows drawn. The full suite passes with mobile-ui#177 through a local path repo.

Screenshots

Nothing looks different. The change is in how often frames reach the phone while you scroll, which a trace shows better than a recording.

  • No visible change

🤖 Generated with Claude Code

Every frame the phone gets while the Log is moving costs its main thread
a pass over the list, and traces put most of the stutter right after one
lands. Until now every visible-range report (every 20 rows) moved the
drawn rows, so nearly every report sent a frame.

While the list moves, a report now keeps the frame as it was unless the
screen is within 50 rows of the edge of the rows drawn, or the end of the
list is within 40 rows with a next page here. The time is pinned for
those renders and for the poll, so a minute ticking over doesn't change
the frame either. When the list comes to rest (mobile-ui's new
on-scroll-end), the rows are drawn around the screen again and the times
catch up.

Once you've scrolled, held pages also go in while the list is at rest,
one after another as they land, until 80 rows sit below the screen. That
gives the next fling room before it needs a page mid-scroll. Opening the
log still only fetches one page ahead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonhamp
simonhamp force-pushed the perf/log-scroll-phase branch from e1bdbfd to 1735d17 Compare October 26, 2026 19:21
@simonhamp
simonhamp marked this pull request as ready for review October 26, 2026 19:22
@simonhamp
simonhamp merged commit 412a5c6 into main Oct 26, 2026
2 of 3 checks passed
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