Skip to content

Show a tab at once, and draw less while switching - #36

Merged
simonhamp merged 1 commit into
mainfrom
perf/tab-switch
Oct 20, 2026
Merged

simonhamp merged 1 commit into
mainfrom
perf/tab-switch

Conversation

@simonhamp

Copy link
Copy Markdown
Member

On Simon's Moto G24, a bottom-nav tap switched the tab straight away but showed the new screen 2 to 3 seconds later, with nothing on screen in between. Most of that is NativePHP's Android PHP build running without OPcache, which a separate php-bin-mobile change is taking on. These are the three app-side parts.

The device key is read once

Every signed request read the device key from the Keychain, and on Android's Keystore that takes about 150 ms. The phone's log showed two or three of those per tab switch. DeviceKey is now a singleton that holds the key once it has read or made it, and forget() drops it with the stored seed. It's the same key for the life of the install, so nothing per request is kept in a singleton.

Tabs draw skeleton rows first

A tab's first frame used to be every row it had kept: about 2,800 views on the Log, which the Moto took over a second to render in PHP and then build. The Log, Notifications, Remotes and the Profile now mount() with a first frame of skeleton rows, and dispatch FirstFrame, a no-op AsyncTask. When it comes back, straight after that frame, the screen shows what it kept and refreshes as before (DrawsSkeletonFirst).

DEVNULL_SKELETON_FIRST turns it off, and phpunit.xml does, so existing tests still see a screen open on what it kept. A new test per screen turns it on and checks the skeleton first, then the kept rows.

Fewer rows for the logs you're not on

The Log sent five kept commits for each log you're not on, about a third of its frame. The log beside yours now gets three, enough for the top of the screen as you swipe, and the log two swipes away gets skeleton rows until you're beside it.

Worth checking

  • The kept rows now arrive in a second frame rather than the first. On a fast phone that may show as a brief flash of skeleton rows.
  • The off-screen previews are smaller, so a fast swipe to the next log can show skeleton rows below the first three commits.

Testing

1,012 tests pass and Pint is clean. I'm putting it on the Moto G24 to compare tab switches.

🤖 Generated with Claude Code

On a slow Android phone a bottom-nav tap took 2 to 3 seconds to show the
new screen, with nothing on screen in between. Three things in the app
made it worse:

- Every signed request read the device key from the Keychain again,
  which takes about 150ms on Android's Keystore, a few times per screen.
  DeviceKey is now one per process and holds the key once read or made.
- A tab's first frame was every kept row, which a slow phone takes
  seconds to render and build. The Log, Notifications, Remotes and your
  Profile now draw skeleton rows first and fill in what they kept as
  soon as a no-op background task comes back (DrawsSkeletonFirst).
  DEVNULL_SKELETON_FIRST turns it off, as phpunit.xml does.
- The Log sent five kept commits for each log you're not on, a third of
  its frame. The log beside yours now gets three, and the one two swipes
  away gets skeleton rows until you're beside it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonhamp
simonhamp merged commit 270cbee into main Oct 20, 2026
1 check passed
@simonhamp
simonhamp deleted the perf/tab-switch branch October 21, 2026 16:24
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