r/webdev • u/techtsp • 28d ago
Question Intermittent ~900ms gap before first paint in mobile Lighthouse on both React and Astro. How would you isolate it?
I'm comparing a React site against an Astro rebuild of the same page. In mobile Lighthouse, both sometimes sit blank for a long time before first paint, and other runs of the exact same page paint fast.
Setup: Lighthouse 13.0.1, Chrome 156, cold loads in separate fresh profiles, default mobile simulated throttling. I kept the traces, network logs and filmstrips.
Here's one matched pair (observed trace timings, not Lighthouse's simulated FCP):
Astro
- CSS done: 203ms
- Last preloaded font done: 286ms
- DOMContentLoaded: 426ms
- First Paint: 1301ms
- FCP: 1320ms
React
- CSS done: 573ms
- Last preloaded font done: 494ms
- DOMContentLoaded: 584ms
- First Paint: 1525ms
- FCP: 1540ms
The filmstrips stay blank right up to those first-paint times. Once painting starts, Paint to DrawFrame is only 10-13ms. So on Astro there's close to 900ms where everything's loaded and nothing shows up.
I don't see a long task on the renderer main thread covering that gap, though I know that doesn't prove the browser was actually idle.
I wondered about animations, so I ran one normal-motion vs reduced-motion pair on the Astro page. Both came back fast (FCP 318ms and 311ms), and the normal one still had its reveal animations, so that told me nothing either way. Desktop loads and a different page also painted quickly in the runs I checked.
One more thing: the fast traces show Scheduler::SetDeferBeginMainFrame events with short true-to-false spans. But the slow traces were captured with Lighthouse's default trace categories, which don't include those scheduler events, so I can't compare yet.
Has anyone run into this? A few things I'd like to figure out:
- How do I tell whether the page is causing the delay, or whether it's Chrome's scheduling or something in the test environment?
- Which trace categories or events would show why the first paint starts late, and not just that it did?
4
u/_sarant 28d ago
4
u/mq2thez 28d ago
Pretty difficult to debug without seeing your code, but I’d guess you’re saying “Astro” but that there are React islands, and possibly even client-only islands. Honestly, even using server-only islands will cause people to do bad things.
More importantly, DCL doesn’t account for async JS, only deferred, so if your JS bundle is async but your HTML is all waiting for it, then you’re still stuck.
2
u/ings0c 28d ago edited 28d ago
Are you testing in incognito mode? I’ve wasted far too much time investigating fictitious performance issues caused by an extension.
And are you using a real HTTP server against a deployed environment versus the Astro dev server? It uses HTTP 1.1, skips optimisations etc, and I usually see a significant boost when running on my actual deployed dev environment.
1
u/ArielCoding 28d ago
Lighthouse’s default trace doesn’t include the compositor scheduler events, so add them with --additional-trace-categories=cc,benchmark, rerun until you catch a slow load, and compare it to a fast one, check when Scheduler::SetDeferBeginMainFrame goes from true to false.
1
u/DVR_Design 27d ago
Blank gap with everything already loaded and no long task usually means the main thread wasn't the problem. Check whether those runs were in a window that was occluded, backgrounded or on a throttled display, since Chrome delays producing frames in that case and you'd see exactly this pattern. Run the slow ones headless or with --disable-backgrounding-occluded-windows and --disable-renderer-backgrounding and see if the gap disappears. For tracing, add the devtools.timeline.frame, cc and viz categories so you get PipelineReporter and BeginMainFrame events, which show whether a frame was requested and what held it up. I'd also compare simulated throttling against plain devtools throttling, because Lighthouse's simulated numbers can differ a lot from observed ones. If the reveal animations start from opacity 0, FCP won't count that content until it's visible, so test once with them fully off, not just reduced motion.
1
u/bkocdur 27d ago
I'd isolate it with a control page before touching either framework. Make a static HTML file with one h1, no CSS, no fonts, no JS, and run it 20 times in the same harness with the same fresh profiles. If the control also lands in the slow bucket some of the time, the page is cleared and it's the environment. If the control is always fast, it's something the page does.
For the second question: I don't think the renderer main thread is where this gap lives. Blank screen with everything loaded usually means either no frame was requested or a frame was produced but not presented. Rerun the slow cases with extra categories (the Lighthouse CLI takes --additional-trace-categories), adding cc, viz, gpu and blink.scheduler. Then check:
One reason this matters even under simulated throttling: as far as I know, Lantern uses the observed FCP timestamp to decide which requests belong in the FCP graph. A late observed paint pulls more requests into that graph, so an environment hiccup can also inflate the simulated FCP you see in the report. That could explain some of the run-to-run swing.
Curious which bucket the control page lands in if you try it.
0
u/Mani_Khan_Web_Master 28d ago
Your own data already points away from the page: CSS, fonts and DOMContentLoaded are done by ~430ms, there's no long task, and Paint to DrawFrame is tiny. That pattern usually means the main thread was fine and the frame was held back downstream, so I'd treat the browser/environment as the suspect until the page proves otherwise.
How I'd separate the two:
-1
u/DesperateNorth2307 28d ago
Rough spot, you've clearly already ruled out the obvious stuff. But comparing a single run of each doesn't tell you much when the delay is intermittent anyway, and the numbers that stand out are Paint to DrawFrame at 10-13ms while the filmstrip sits blank for ~900ms after DOMContentLoaded: the page is ready, something above it is waiting on a frame. Rerun the same page with headless off, or just record a trace in a visible window, and if the gap vanishes it's the harness rather than anything React or Astro did.
-1
u/Formal-Drag-8788 28d ago
You're calling it intermittent but showing one matched pair. The two gaps are ~875ms and ~940ms on two completely different frameworks, which points at the harness before it points at React or Astro. How many runs did you actually collect per site?