Skip to content

docs: correct the request chain change for simulated throttling - #27

Merged
ChristopherPHolder merged 1 commit into
mainfrom
docs/fetch-chains
Nov 27, 2026
Merged

ChristopherPHolder merged 1 commit into
mainfrom
docs/fetch-chains

Conversation

@ChristopherPHolder

Copy link
Copy Markdown
Collaborator

Closes #26.

What

Corrects change 3 in docs/simulated-throttling.md and the section behind it:

  • XHR is already linked. linkCPUNodes makes the task with XHRReadyStateChange at readyState 4 depend on the request. Only fetch is missing.
  • The signal is named. Lighthouse's trace has no event in the continuation task that names the request. The v8::Debugger::AsyncTaskScheduled/AsyncTaskRun flow events in disabled-by-default-v8.inspector link the task that sent the fetch to the task that continues after it. Lighthouse already turns on async stacks but doesn't record that category.
  • Change 3 says how. A task that runs an async task scheduled by the task that sent a fetch depends on that request, if the response arrived first.
  • Change 5 records the category and adds core/gather/gatherers/trace.js to its files. The Order section says change 3 can be tried with additionalTraceCategories, and that the size of the category on a real app decides whether Lighthouse can record it by default.
  • lighthouse#15897 is related, not the same. It is about ES module import chains, and the cause it finds is TCPConnection charging no time to first byte on a warm h2 connection.

Verified

  • Recorded the fixture soft navigation through Lighthouse 13.6.0 (Chrome 157) with additionalTraceCategories: 'disabled-by-default-v8.inspector'. The flow events link the click task that sends /api/route to the task that sends /api/details. The trace went from 0.74 MB to 0.76 MB.
  • Read linkCPUNodes, ConnectionPool and AsyncJSCallsHandler in @paulirish/trace_engine 0.0.67, and prepare.js and trace.js in Lighthouse 13.6.0.
  • pnpm nx format:check passes. Only Markdown changed.
tmp/probe/lh-async.mjs: the recording
// Through Lighthouse: with disabled-by-default-v8.inspector added, does the soft navigation step's trace
// link the task that continues after a fetch to the task that sent it?
import { startFlow } from 'lighthouse';
import puppeteer from 'puppeteer';
import { softNavigationConfig } from '../../packages/lighthouse-soft-navigation/dist/index.js';
import { startAppServer } from '../../packages/lighthouse-soft-navigation-e2e/fixtures/app-server.mjs';
const server = await startAppServer();
const browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox'] });
try {
  const page = await browser.newPage();
  const flow = await startFlow(page, { config: softNavigationConfig(), flags: process.env.NO_CAT ? {} : { additionalTraceCategories: 'disabled-by-default-v8.inspector' } });
  await flow.navigate(`${server.origin}/`);
  await flow.navigate(async () => { await page.click('#products-link'); }, { throttlingMethod: 'devtools' });
  const events = flow.createArtifactsJson().gatherSteps[1].artifacts.Trace.traceEvents;
  const sends = events.filter((e) => e.name === 'ResourceSendRequest' && /\/api\//.test(e.args.data.url));
  const tid = sends[0].tid, pid = sends[0].pid;
  const tasks = events.filter((e) => e.pid === pid && e.tid === tid && e.name === 'RunTask' && e.ph === 'X');
  const taskOf = (e) => tasks.find((t) => t.ts <= e.ts && e.ts <= t.ts + t.dur);
  const t0 = sends[0].ts, ms = (ts) => ((ts - t0) / 1000).toFixed(1);
  for (const s of sends) console.log(`send ${new URL(s.args.data.url).pathname} @${ms(s.ts)} in task @${ms(taskOf(s).ts)}`);
  const flowEv = events.filter((e) => e.name.startsWith('v8::Debugger::AsyncTask') && (e.ph === 's' || e.ph === 'f'));
  const byId = new Map(); for (const e of flowEv) (byId.get(e.id + e.name) ?? byId.set(e.id + e.name, []).get(e.id + e.name)).push(e);
  console.log('inspector flow events:', flowEv.length);
  for (const [, pair] of byId) {
    const s = pair.find((e) => e.ph === 's'), f = pair.find((e) => e.ph === 'f');
    if (!s || !f || s.name !== 'v8::Debugger::AsyncTaskScheduled') continue;
    const from = taskOf(s), to = taskOf(f);
    if (!from || !to || from === to) continue;
    const sentFrom = sends.filter((x) => taskOf(x) === from).map((x) => new URL(x.args.data.url).pathname);
    const sentTo = sends.filter((x) => taskOf(x) === to).map((x) => new URL(x.args.data.url).pathname);
    if (!sentFrom.length && !sentTo.length) continue;
    console.log(`scheduled in task @${ms(from.ts)} [sends ${sentFrom}] -> runs in task @${ms(to.ts)} [sends ${sentTo}]`);
  }
  console.log('trace size MB:', (JSON.stringify(events).length / 1e6).toFixed(2));
} finally { await browser.close(); await server.close(); }

XHR is already linked by linkCPUNodes, so only fetch is missing. The
link a fetch needs is in the v8::Debugger::AsyncTask flow events of
disabled-by-default-v8.inspector, which Lighthouse would have to record.
lighthouse#15897 has the same symptom but a different cause.

Closes #26
@ChristopherPHolder
ChristopherPHolder merged commit 9099a40 into main Nov 27, 2026
1 check 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.

docs: correct the request chain change in simulated-throttling.md

1 participant