Skip to main content

2026-11-30 · 11 min read

Turning a spare Galaxy A21s into a test phone: what a real low-end device shows that emulation can't

PerformanceDebugging

Translated from the Chinese original: read it in Chinese

For this site's mobile version, I had only ever checked by shrinking the browser to 390px wide in Playwright. That shows layout problems but cannot measure performance: the emulator runs on the desktop's i7, so the "phone" is not slow at all.

It happens that I have a spare Galaxy A21s at home. It is a 2020 entry-level phone: Exynos 850, Mali-G52 GPU, 3.6 GB RAM, Android 11. As a test phone it is a good stand-in for "the cheap phone in a visitor's hand".

How to connect: wireless debugging, no cable

The combination I ended up with:

  1. Turn on "Wireless debugging" in the phone's developer options and pair with the desktop once using the pairing code (adb pair)
  2. adb forward tcp:0 localabstract:chrome_devtools_remote: connect the phone Chrome's DevTools socket to a free port on the desktop (this is also the route chrome://inspect uses)
  3. Playwright connects with chromium.connectOverCDP(), and what it drives is the real Chrome on the phone

Playwright does have _android which can open the phone's Chrome directly, but it needs a flag to be turned on in the phone's Chrome first, and if it is not, it hangs silently (I tried it earlier with a tablet). Going through CDP needs no change to the phone's settings.

To test a version not yet deployed on the desktop, I can use adb reverse tcp:3201 tcp:3201: localhost:3201 on the phone connects straight to localhost:3201 on the desktop. The test server does not need to listen on the LAN, and I do not have to touch the Windows firewall. I tried it with a small server listening only on 127.0.0.1, and Chrome on the phone could open it.

What I measure

For every page:

  • LCP and CLS: with PerformanceObserver, recording which element caused them
  • How many times per second the Hero background is actually drawn: the mobile Hero is a Canvas 2D 3D projection I wrote myself, and each frame starts with a clearRect, so counting clearRect calls on the Hero canvas is enough
  • How smooth touch scrolling is: CDP's Input.synthesizeScrollGesture sends a real touch gesture, and then I measure two kinds of fps (the reason for two is explained below)
  • console errors, page exceptions, failed requests; plus screenshots

Trap 1: one blank tab froze the connection

The very first connection hung. The connectOverCDP log stopped at <ws connected> and timed out after 60 seconds.

Turning on DEBUG=pw:protocol showed that all 43 CDP commands sent had received responses, so Playwright was not waiting for a reply but for some event. There was a tab on the phone whose URL was an empty string, left over from some earlier time. When Playwright connects, it waits for every existing tab to "finish its first navigation", and this one would never navigate, so it waited forever.

The fix is that before connecting, I use native CDP to navigate tabs with an empty-string URL to about:blank. The tab was empty anyway, so nothing is lost.

A few other small traps:

  • With wireless debugging on, the same phone shows up in adb devices on two lines (IP:port and the mDNS name), and with a USB cable plugged in but "allow" not tapped there is another unauthorized line. Then any adb command without -s complains "more than one device", so the multiple connections of one phone have to be merged into one by serial number
  • On Android 11, dumpsys power writes getWakefulnessLocked()=Awake, while Android 16 writes mWakefulness=Awake. If you only recognize the latter, the A21s is always treated as having its screen off
  • After Android Chrome creates a new tab, it navigates once more to about:blank by itself. If you goto right after opening the tab, that interrupts you

Trap 2: rAF fps is not the screen's fps

At first I measured fps during scrolling with requestAnimationFrame, and the home page was 35 to 44. But in Android Chrome, scrolling is done by the compositor, and when the main thread is slow, the screen does not necessarily stutter.

To find out how many frames the screen really sends out, you have to ask Android's SurfaceFlinger: dumpsys SurfaceFlinger --latency <layer> lists the display times of the last 127 frames. The trouble is finding the right layer: the one with the most similar name, SurfaceView - com.android.chrome/…, has 0 frames while scrolling, and the web content is actually drawn on com.android.chrome/ChromeChildSurface#0 (when Surface Control is on in chrome://gpu), which has 100 frames when scrolling 1500px.

With the screen's numbers, the home page is 44 to 46 fps, a bit better than rAF, but still the lowest on the site.

Results

Live site, Wi-Fi, each page measured at least twice:

PageLCP (first visit)Scroll: screen fpsDropped frames
Home (before the fix)1.55 s44–4620–26
Blog list1.04 s582
One article1.08 s56–572
Home radar1.48 s592
Election map1.05 s535
  • All LCP values are within 2.5 seconds. On a real low-end phone over Wi-Fi, the home page is 1.2 to 1.55 seconds (earlier, with an emulator, 4x CPU throttling and slow 4G, it measured 2.5 to 3.5 seconds, but the network conditions are very different, so the two numbers cannot be compared directly)
  • The Hero background is not the burden: sitting at the top of the home page it draws 30 times per second (exactly the designed cap), costs only about 32 ms of main thread per second, and has no long frames
  • No console errors, no horizontal overflow; /blog and the election map have a little layout shift (CLS 0.058 and 0.025), still inside the 0.1 "good" range, but I fixed those later too (see below)

WebGPU: chrome://gpu says yes, in practice no

chrome://gpu's Graphics Feature Status says WebGPU is "Hardware accelerated". But calling navigator.gpu.requestAdapter() in a page returns null, and Chrome prints "No available adapters." Using compatibility mode with featureLevel: "compatibility" also gives null.

Further down the same page: Vulkan: Disabled. WebGPU on Android goes through Vulkan, so this phone cannot use it. WebGL2 works fine (the renderer is Mali-G52).

The mobile version of the site never uses WebGPU anyway (screens narrower than 768px always get the lightweight Canvas 2D version), so this does not affect visitors, but "chrome://gpu says it can" does not mean "it works": you only know once you actually call requestAdapter().

(The content of chrome://gpu is wrapped in several layers of shadow DOM, so document.body.innerText returns nothing, and you have to walk every shadowRoot yourself.)

Why the home page was the worst: a 0 changed to 0.01

Home page scrolling had long frames of 120 to 160 ms, but breaking them down, there was no script at all inside, and style and layout took only 1 to 2 ms. So it was not a JavaScript problem.

The script has a --css parameter that injects extra CSS into each page, which lets me A/B "does it get smoother if I remove this effect" without changing code. In the first round I removed, one at a time, the NavBar's backdrop-filter, the full-page paper-texture overlay, the Hero canvas, all images, shadows and filters, and the results stayed in the original range, with no culprit among them.

The turning point was scrolling the same page twice: scroll to the bottom, jump back to the top, scroll again. The second pass was 59 fps with not one slow frame. The slow frames only appeared in the first pass, and all of them fell at the moment "a new section enters from the bottom edge of the screen". So the problem is not scrolling itself but the cost of content appearing for the first time.

Another A/B looking only at the first pass (each variant measured twice, interleaved with the baseline):

First-pass scrollScreen fpsDropped frames
Original50, 5116, 12
Switched to system fonts48, 5117, 12
Turned off the character-by-character heading fade-in49, 5212, 12
Turned off the fade-in of 48 sections57, 582, 4
Fade-in start changed from opacity 0 to 0.0158, 583, 1
Control: injecting an identical copy of the keyframes51, 5115, 13

Sections on the home page fade in when scrolled to. In supporting browsers this is a pure CSS scroll-driven animation (animation-timeline: view()), starting from opacity: 0 and 20px lower. My guess is that Chrome does not paint a layer at opacity 0 ahead of time, and only rasterizes it on the spot once it starts fading in. This phone's chrome://gpu happens to say Multiple Raster Threads: Disabled, so only one thread rasterizes, and 48 sections doing this in turn keeps dropping frames. With the start at 0.01, Chrome paints them before they come into view. One percent opacity cannot be told apart by eye.

One thing I did not resolve: a version that also starts from opacity 0 but only fades in without moving does not stutter either.

Finally I verified it through the normal process: I brought up the fixed version on the test server, had the phone reach the desktop through adb reverse, and measured against the live site twice each, interleaved. The home page's first pass went from 47 fps with 17 to 18 dropped frames to 56 fps with 4.

This change has a side effect. The accessibility check (axe) treats opacity 0 elements as hidden and skips them, but 0.01 counts as visible faint text: scanning the home page on desktop without "reduce motion" adds 29 contrast failures. The site's a11y tests were already run with reduce motion on; that path does not use this animation, so sections not yet scrolled to stay at opacity 0. The tablet check script did not have it on, and that was also added this time.

An emulator runs on the desktop CPU and GPU and cannot measure this kind of thing; you have to switch to a real cheap phone to see it.

Layout shift: the search box that appears after hydration

/blog's CLS of 0.058 came from the search box at the top. It needs JS to work, so it was originally hidden (hidden) and shown after React hydrated, so people without JS would not see a box that does nothing when pressed.

The problem is that when the search box popped up, the article list was already painted, and the whole page got pushed down. On the A21s that moment fell about 1.8 seconds after load. Going back and measuring with Playwright on the desktop, it was actually there too (0.037 at 1280px width, 0.059 at 411px), only noticed on the phone.

The fix is to show it from the start and hide it only when the browser reports "no JS". CSS has a media query @media (scripting: none) for exactly this, and in Tailwind v4 you just write noscript:hidden.

The election map's 0.025 is another kind: the "year" row only gets buttons once the data arrives, and before that it is 6px tall, becoming 38px when data arrives; the detail drawer at the bottom of the phone also grows from 50px to 92px. Both were fixed by reserving the height with min-height.

Both are reproducible on the desktop too: Playwright at 411px width, delay the data files by 1.5 seconds with page.route, and collect layout-shift entries with PerformanceObserver. Each one comes with sources saying which element moved from where to where, and looking at whose height changed tells you who did the pushing.

After the fix, measuring a first visit again on the phone gives 0 for both pages.

How to use it from now on

One script, scripts/phone-check.mjs: by default it measures 5 pages of the live site, --cold measures a first visit, --base http://localhost:<port> measures a version not yet deployed, and --css does A/B. Every page is scrolled twice; if the first pass stutters and the second is smooth, that is the "cost of the first appearance". It changes no setting on the phone; and if it finds another program already connected to the same phone's DevTools, it stops, because with two things operating one low-end phone at once, neither set of numbers can be used. This really happened once: another job was crawling the whole site with the same phone.

Type to search projects and posts too