Skip to the content

Local experiments

Nine experiments of 2026-10-07 to 2026-10-16: listener order, idle timers, DriftLag, workers in a block, a sustained load, a hang seen by another page, an async context, a frame off the screen.

We did nine experiments in this repository from 2026-10-07 to 2026-10-16. They measured facts that no document gives.

E1 measured the order of the event listeners at the target of an event. E2 measured the timers of an idle page in three engines. E3 measured the calibrated DriftLag on the same machine. E4 measured when the IndexedDB writes and the fetches of a worker complete while the main thread is blocked, also in Safari. E5 measured DriftLag during a sustained load.

E6 measured the other output APIs of a worker during a block. E7 measured what another page of the origin sees of a hang, also in Safari on iOS. E8 measured the cost of an async context on the main thread, and its effect on the values of the monitors. E9 measured the animation frames, the idle callbacks and the timers of a cross-origin frame off the screen.

The results changed the library in five ways. An explicit hook, not the order of the listeners, records the final values before each flush. DriftLag subtracts a calibrated baseline. The probes that use setTimeout(0) start in a message task. A probe of message tasks must show an idle thread before the baseline of DriftLag increases.

E4 and E6 found a limit of the hang reports and of the hang journal in WebKit and Safari. E7 found a way around it: the peer hang watch. E8 did not change the library. It gives the data for the default context manager of otel-ts and for an add-on of lag. E9 made the frame-timing monitor pause while its frame is off the screen.

E1: the order of listeners at the target

Question. When two listeners are on the target of an event, does a capture listener start before a bubble listener that the page added earlier? The DOM standard says yes: at the target, the capture listeners start in the capture pass, and the other listeners start in the bubble pass.

Method. The experiment used Vitest browser mode with the Playwright provider. In each case, it added a bubble listener first and a capture listener second. Then it dispatched one event and recorded the listener that started first.

TargetChromium 145.0.7632.6 (headless)Firefox 146WebKit (Safari 26.0)
window, custom EventBubble (the order of registration)CaptureCapture
window, PageTransitionEvent("pagehide")Bubble (the order of registration)CaptureCapture
document, custom EventCaptureCaptureCapture
document, Event with bubbles: trueCaptureCaptureCapture
Element (document.body)CaptureCaptureCapture

Meaning. The target of visibilitychange, freeze and resume is document. Thus the capture listeners of the monitors start before the listeners of an exporter in all three engines. The target of pagehide and pageshow is window. In Chromium, the listener that the page added first starts first there. Thus an exporter that added its pagehide listener before the monitors can flush before the monitors record their final values.

Change in the library. The fix does not depend on the order of the listeners. AllMonitorHandles.flush() records the values that the monitors keep until a checkpoint. At the start of each flush, otel-ts starts each onBeforeFlush listener. The setup connects the two: otel.onBeforeFlush(() => monitors.flush()).

Later, the state machine became the package page-lifecycle-tracker, with a tracker that the page shares. The otel-ts library flushes in its export phase, after the monitors recorded the transition.

Refer to setup-all-monitors.ts, LifecycleStateMachine.ts and the quick start. The browser test lifecycle.test.ts keeps a check of the document case.

E2: the timers of an idle page

Question. How long does one step of a chained setTimeout(5) take on an idle page? Which lag does the old DriftLag report on an idle page? The old DriftLag chained 20 steps of 5 ms and reported the elapsed time minus 100 ms.

Method. The experiment used the headless engines of Playwright on Windows 11. It measured each value on an idle page.

MeasurementChromium 145Firefox 146WebKit (Safari 26.0 build)
Median step of setTimeout(5)5.7 ms16 ms15 ms
Shortest step5.0 ms9 ms13 ms
Old DriftLag, idle median lag15.8 ms211 ms211 ms
setTimeout(0) from a setInterval callback (8th repeat), median5 ms16 ms16 ms
setTimeout(0) from a message task, median0 ms0 ms15 ms
requestIdleCallbackYesYesNo
performance.interactionCountYesYesYes

Meaning.

  • For a 5 ms timeout, Firefox and WebKit on Windows use the 15.6 ms timer tick of the system. Chromium asks for a 1 ms tick. This agrees with the timer rules in clocks and timers.
  • On an idle page, the old DriftLag reported more than 200 ms of lag for each 100 ms window in Firefox and WebKit, and 16 ms in Chromium. Thus the old probe measured the timer granularity, not the lag.
  • A setTimeout(0) from a nested timer gets the 4 ms clamp in Chromium, and the system tick in Firefox and WebKit. From a message task, Chromium and Firefox start it at once.
  • The WebKit build for Windows is not Safari on macOS. Safari on macOS aligns nested timers to a grid of 4 ms, and of 30 ms in Low Power Mode (WebKit DOMTimer.cpp).

Change in the library. MacrotaskLag and SchedulingFairness start each measurement in a message task (message-task.ts). A message task has the timer nesting level 0, thus the setTimeout(0) measures the queue and not the clamp. Without MessageChannel, MacrotaskLag starts the measurement in its setInterval callback and has a floor of approximately 4 ms.

E3: the calibrated DriftLag

Change. DriftLag subtracts the idle duration of one step. The baseline is the mean of the recent steps that are not longer than the median plus max(4 ms, half of the median). The lag of a window is its duration minus the number of steps multiplied by the baseline (DriftLag.ts).

Method. The experiment used the same machine and engines as E2. It recorded approximately 30 idle windows, then blocked the main thread for 300 ms.

MeasurementChromium 145Firefox 146WebKit
Baseline step5.7 ms15.5 ms15.6 ms
Idle median lag (approximately 30 windows)0.1 ms−0.3 ms−0.4 ms
Idle p90 lag3.1 ms1.3 ms1.6 ms
Lag after a 300 ms block297.4 ms282.7 ms294.6 ms

Idle lag of DriftLag before and after the calibration

Before the calibrationAfter the calibration
Chromium 145Firefox 146WebKit050100150200Median lag of an idle 100 ms window (ms) →0.1 ms-0.3 ms-0.4 ms
Show the data as a table
Median lag of an idle 100 ms window, before and after the calibration of DriftLag
EngineBefore the calibrationAfter the calibration
Chromium 14516 ms0.1 ms
Firefox 146211 ms-0.3 ms
WebKit211 ms-0.4 ms
Experiments E2 and E3, 2026-10-07, Windows 11, the headless engines of Playwright. The labels give the values after the calibration.

Meaning. The idle error went from 15.8 ms to 211 ms down to less than 0.5 ms. The resolution of the measurement is one step. A block can start immediately after a step, thus the lag of a block can be less than its duration by up to one step. That step is 16 ms in Firefox.

A first version used the median as the baseline. It gave an idle median lag of 3.3 ms in Chromium, because timer jitter is skewed to the right. Thus the baseline is a mean of the steps that are not blocks.

Check in the repository. The browser test drift-accuracy.test.ts keeps a check of the two properties. The idle median must be less than 5 ms from 0, or 10 ms in a window without focus. On macOS, the timers of an app that is not in front can be late. After a 300 ms block, the largest lag must be more than 300 ms minus the baseline minus 10 ms, and less than 340 ms. Without focus, the margin is 20 ms, because some steps of Safari are late and its baseline is longer than its usual step.

A later finding. The granularity can change while a page is open. The CDP tests found such a change in Chromium on Windows. After the page was hidden and shown again, the steps took 15.6 ms instead of 5.5 ms. The baseline of the last 100 steps followed the change slowly, and DriftLag reported windows of 160 ms of lag on an idle page. Thus DriftLag accepts a row of 10 steps that agree with each other as a new granularity (DriftLag).

E4: the input and output of workers during a main-thread block

Question. Can a worker write to IndexedDB and send a request while the main thread of its page is blocked? The hang report and the hang journal of the worker monitor depend on it.

Method. The probes are in worker-io.ts. Each probe starts an operation in a worker, and then it blocks the main thread for 2 s. It records when the operation completes, as the time after the start of the block. The experiment used the Playwright builds on Windows 11, with these probes:

  • A dedicated worker writes one record to IndexedDB.
  • A dedicated worker sends a fetch with keepalive.
  • A shared worker writes to IndexedDB and then sends a fetch each 100 ms, on its own timer. The probe counts the operations that complete during the block, with a margin of 100 ms at the start and at the end. The shared worker uses its own timer, because a message from the page can also wait.
  • A service worker (public/lag-sw-probe.js) does the same as the shared worker, on its own timer of 100 ms (2026-10-08). A service worker operates outside the page, thus it could possibly keep the hang journal where a dedicated worker cannot.

A CI job operated the same probes in Safari 26.6.2 on a GitHub macOS runner, through safaridriver (2026-10-08). The Safari column comes from the log of that job. The log gives the count of the service worker. For the other probes, the log shows that the tests passed with the expectations of WebKit.

MeasurementChromiumFirefoxWebKitSafari 26.6.2, macOS (CI log)
IndexedDB write of a dedicated worker, complete after7 ms36 ms (58 ms in a second run)2015 ms (2008 ms in a second run)After the block
fetch with keepalive of a dedicated worker, complete after19 ms14 ms2013 msAfter the block
Operations of a shared worker that completed during the block, of all its completed operations18 of 2816 of 260 of 260
Operations of a service worker that completed during the block, of all its completed operations18 of 2817 of 270 of 290 of 27

In WebKit, a message that the page posted to a shared worker immediately before the block also arrived only after the block, at 2003 ms.

Meaning. Chromium and Firefox complete the IndexedDB requests and the network requests of a worker during the block. WebKit completes them on the main thread of the page, after the block. This is also true for a shared worker and for a service worker. Safari 26.6.2 on macOS behaves the same as the WebKit build of Playwright for Windows.

In WebKit and Safari, the timer of the worker continues, thus the worker detects a hang. But it cannot send its hang report or write the hang journal until the main thread operates again. Thus there, a page that does not survive its hang leaves no record and no report. A service worker is no way out: its writes and fetches also wait for the main thread of the page.

Change in the library. The code does not change. The pages worker lag and survivorship bias give the limit.

Check in the repository. The browser test worker-io.test.ts operates the four probes in Chromium, Firefox, WebKit and Chrome, and in the CI job in Safari. In WebKit and Safari, it expects that the write and the fetch complete after the block. It also expects that the shared worker and the service worker complete no operation during the block there.

In the other browsers, it expects the write and the fetch before the end of the block. A completion 25 ms or less before the end of the block counts as a wait, because the worker and the page read different clocks. On a busy CI runner, a write of Firefox completed after 1141 ms of a block of 2000 ms: slow, but not a wait. It also expects more than 5 operations of the shared worker and of the service worker there. Thus the test fails if an engine changes its behavior.

The browser test hang-journal.test.ts skips itself where a probe finds that the IndexedDB requests of a worker wait for the main thread. The probe uses a block of 500 ms. Thus the skip comes from a measurement, not from the name of the browser. In the CI log, the test skips itself in Safari.

E5: DriftLag during a sustained load

Question. Does DriftLag report a sustained load of tasks of the same length? The baseline comes from the recent steps. Thus a load that makes all steps longer can look like a new timer granularity.

Method. The page calibrated DriftLag for 2 s. Then it kept the main thread busy for 4 s with a chain of equal tasks, and then it was idle for 1.5 s. The experiment used the Playwright builds on Windows 11 (2026-10-08).

There were two loads. In the first, each task of 20 ms starts the next task with a message. In the second, each task of 30 ms starts the next task with setTimeout(0), thus 4 ms later. The table gives the lag as a part of the time of the windows.

LoadChromium 145Firefox 146WebKit
Message tasks of 20 ms85% for 2.5 s. Then the baseline increased to 39 ms, and the lag decreased to 6%.25% for 1 s. Steps of 20 ms are in the jitter limit of steps of 15.6 ms, thus the baseline increased to 20 ms. The lag was 0 after 2 s.Approximately 0 after 0.5 s. A row of steps of 31 ms was a new granularity after 10 steps.
Timer tasks of 30 msApproximately 0 from the start. A row of steps of 34 ms was a new granularity.67% for 2 s. Then the median increased to 42 ms, and the lag decreased to 12%.66% for 2 s. Then the median increased to 41 ms, and the lag decreased to 14%.

Meaning. The calibration of E3 hides a sustained load. The lag decreased to less than 15% in each case within 4 s, and to approximately 0 in three of the six cases. The steps of a busy thread agree with each other, or the median becomes a busy step. The worker monitor measures these loads correctly, because it does not use the timers of the page.

Change in the library. A probe of message tasks must show an idle thread before the baseline increases (DriftLag). On an idle thread, a message starts at once. On a busy thread, it waits for the current task. A check is an idle probe, 3 steps, and a second idle probe. The browser tests of the change found three behaviors of the engines:

  • A probe changes the timing. A probe keeps the thread awake. In Chromium, a probed step took 0.7 ms less than an idle step, and 2.5 ms less one time. The next step took up to 3 ms more (11 ms instead of 8 ms). A first version used the probed step as the idle duration, and gave 48 ms of lag in each window of an idle page in Chrome. Thus the probed step and the next step are not recent steps.
  • Messages wait in WebKit for Windows. A chain of messages posted 84 messages in 100 ms there, and more than 13,000 in Chromium and Firefox. After an idle period, the first message waited 12 ms to 17 ms: the next timer tick of the system. Thus the probe finds no idle step there, and DriftLag operates as before the change.
  • Irregular steps in Firefox. For some seconds after a load, the steps changed between 8 ms and 16 ms. A first version lowered the confirmed value to the recent baseline of one window. Then each window had 6 ms to 10 ms of lag. Thus the confirmed value decreases only to the highest recent baseline of 3 windows.

Result. The browser test drift-load.test.ts uses a load of 3 s. The table gives the lag in the second half of the load. The rows of Windows 11 come from three runs of four browsers at the same time. The rows of GitHub runners come from the logs of one CI run:

BrowserPlatformMessage tasks of 20 msTimer tasks of 30 ms, 4 ms apart
Chromium 145Windows 11, three runs80% to 86%78% to 85%
Chrome 153Windows 11, three runs80% to 86%79% to 85%
Firefox 146Windows 11, three runs24% to 29%53% to 72%
WebKit (Playwright)Windows 11The test skips itselfThe test skips itself
Chromium 145Linux, GitHub runner87%85%
Firefox 146Linux, GitHub runner75%84%
WebKit (Playwright)Linux, GitHub runner60%79%
Safari 26.6.2macOS, GitHub runner62%77%

In WebKit on Linux and in Safari on macOS, a probe on an idle page measured 0 ms of busy time. Thus only the WebKit build for Windows makes a message wait.

After the load, the median lag of a window was between −9 ms and 8 ms, in windows of approximately 100 ms. In Firefox on Windows, an idle step already takes 15.6 ms. Thus a step that waits for a task of 20 ms gives only 4.4 ms of lag.

Check in the repository. drift-load.test.ts expects more than 10% lag in the second half of each load. After the load, it expects a median lag of less than the idle median lag before the load plus 10% of a window. A negative idle median counts as 0. It skips itself if a probe on an idle page posts fewer than 400 messages in 100 ms. The WebKit build for Windows posts 122 to 278 messages, and the other WebKit builds in CI post 580 to 920.

The check after the load does not use the windows in which the browser stopped its timers. In the iOS Simulator, it also skips itself when the timers of the browser were slower after the load (refer to the limits of the tests).

The unit tests of DriftLag.load.test.ts use a simulated thread with a timer queue and a message queue. They simulate the three behaviors above.

E6: the other output APIs of a worker during a block

Question. E4 found that IndexedDB and fetch of a worker wait for the main thread in WebKit. Can a worker of a blocked page write or send through another API? Each one could keep the hang journal in WebKit and Safari.

Method. The probes are in worker-io.ts. The worker first prepares the operation, for example it opens the file. Then the page posts a message that starts the operation, and it blocks its main thread for 2 s. The worker records when the operation completes.

For a WebSocket, a server in Node (commands/probe-socket.ts) records when the message arrives, with the wall clock of the machine. The page uses the same wall clock, through performance.timeOrigin.

Three operations use the origin private file system (OPFS). They are a write and a flush through a FileSystemSyncAccessHandle, a write through a FileSystemWritableFileStream, and a file lookup. The other operations are Cache.put(), an asynchronous and a synchronous XMLHttpRequest, and a WebSocket message. The Playwright builds operated on Windows 11, in two runs (2026-10-08). Safari 26.6.2 operated in the CI job on a GitHub macOS runner, in two runs.

Operation of a dedicated worker, complete afterChromium 145 and Chrome 153Firefox 146WebKit (Playwright, Windows)Safari 26.6.2, macOS
IndexedDB write42 ms44 ms2005 ms to 2036 ms2023 ms
OPFS: sync access handle write and flush6 ms to 45 ms2 ms to 40 msNo OPFS in this build2001 ms to 2002 ms
OPFS: writable stream write and close13 ms to 16 ms37 ms to 43 msNo OPFS in this build2003 ms to 2008 ms
OPFS: getDirectory() and getFileHandle()2 ms to 3 ms8 ms to 14 msNo OPFS in this build2000 ms to 2002 ms
Cache.put()29 ms to 98 ms28 ms to 75 ms2011 ms to 2023 ms2004 ms to 2009 ms
XMLHttpRequest30 ms to 103 ms2073 ms2014 ms2005 ms
Synchronous XMLHttpRequest16 ms to 315 ms2017 ms to 2065 ms2012 ms to 2176 ms2004 ms to 2058 ms
WebSocket message, at the server0 ms to 3 ms2000 ms to 2002 ms2016 ms to 2048 ms2001 ms

Meaning. In WebKit and Safari, each output API of a worker waits for the main thread of the page. Thus no API of a worker can keep the hang journal there. In the source of WebKit, the worker side of each API posts its work to the main thread of the web process. Examples are WorkerThreadableLoader, IDBConnectionProxy, WorkerFileSystemStorageConnection, CacheStorageConnection and WorkerThreadableWebSocketChannel.

In Firefox, the storage APIs of a worker complete during the block, but an XMLHttpRequest and a WebSocket message wait. Thus Firefox operates them through the main thread. The hang report of the worker uses fetch, which completes during the block in Firefox (E4). Chromium completes all of them during the block.

Change in the library. The code of the journal does not change. The peer hang watch uses another page of the origin instead of a worker (E7).

Check in the repository. worker-io.test.ts operates each probe in Chromium, Firefox, WebKit and Chrome, and in the CI job in Safari. It expects each operation after the block in WebKit and Safari. In Firefox, it expects an XMLHttpRequest and a WebSocket message after the block. It expects all others during the block. A test skips itself where the worker does not have the API.

E7: what another page of the origin sees of a hang

Question. E6 found no output API that a worker can use during a hang in WebKit. Another page of the origin has its own main thread. Can it see the hang of a page, and the end of a page that closes during its hang?

Method. The test page watches a peer page (peer-tab.test.ts). A command opens the peer page as a second top-level page: with Playwright, or as a new window with WebdriverIO in Safari. The peer page holds a Web Lock until it closes. Its main thread and a dedicated worker each send a heartbeat through a BroadcastChannel each 100 ms. It also sends a message in pagehide.

The peer page then blocks its main thread for 4 s, and the test page records the heartbeats and examines the lock.

At the start of the block, the peer page sends a message with the time. The measurements start at that time, because the answer to the command that starts the block can come late. In one run of Safari on a GitHub macOS runner, the answer came more than 1 s after the start of the block. In a second case, the peer page blocks for 20 s, and the test closes it after 2 s. The test page asks for the lock of the peer page, and it records when it gets the lock. The measurements use the times of events, not of timers, because the test page can be hidden.

The Playwright builds operated on Windows 11 in three runs, and on Linux in CI. Safari 26.6.2 operated on a GitHub macOS runner, also with a block of 90 s. Safari 26.5 operated in the iOS Simulator of the same runner, with Xcode 26.6.

MeasurementChromium 145 and Chrome 153Firefox 146WebKit (Playwright)Safari 26.6.2, macOSSafari 26.5, iOS Simulator
The test page operates during the blockYesYesYesYesYes
The lock of the blocked page stays held during the blockYesYesYesYesYes
Largest gap of the heartbeats of the worker114 ms to 210 ms115 ms to 123 ms3994 ms to 4088 ms (the block)4070 ms to 4088 ms (the block)Not measured (refer to the note)
The test closes the blocked page: the lock comes free0.5 s to 8 s later14 ms to 2.8 s laterWindows: 12 ms to 52 ms later. Linux: 3 s laterAt the end of the block, also after 90 s3.4 s to 5.3 s later
pagehide of the closed pageNoYes, 13 ms after the closeWindows: no. Linux: at the end of the blockYes, at the end of the blockNo

Note on iOS. The earlier iOS result for the gaps of the heartbeats was not a measurement. Safari on iOS operates only the visible tab. While the test page is visible, the peer page sends no heartbeats, thus the gap was the full interval. The test checks that heartbeats arrived before and after the block, and it skips itself on iOS. The lock and the close results of the iOS column are real checks.

Meaning. In each engine, another page of the origin operates during the block, and the Web Lock of the blocked page stays held. Thus the other page sees the silence of the hung page, and it knows that the page still exists. The BroadcastChannel of a worker waits for the main thread in WebKit and Safari, as the other output of a worker (E6). Thus the hung page itself cannot send a message.

The engines end a page that the user closes during a hang in three ways:

  • Chromium, Safari on iOS and the WebKit build for Windows stop the page. The lock comes free without pagehide. Then another page can report the hang.
  • Firefox stops the blocked script, and Safari on macOS lets the script continue until it ends. Then the page closes normally, with pagehide. Thus the page itself can report its hang at its close.
  • The WebKit build for Linux releases the lock after 3 s, but the page continues until the end of its script.

Change in the library. The peer hang watch uses both paths. A visible page holds a Web Lock and sends a heartbeat each second. Another page reports a page whose lock comes free after 5 s or more without a heartbeat (lag.hang.source: "peer"). A page that closes at the end of a hang reports its own hang (lag.hang.source: "self").

Check in the repository. peer-tab.test.ts keeps the measurements of each engine. It expects the silence, the held lock, the BroadcastChannel of a worker, and the way in which each engine ends a closed page. peer-hang-watch.test.ts operates the library in two pages, and expects the report of the right page in each engine. It skips itself in Safari on iOS, because Safari there operates only the visible tab.

E8: the cost of an async context in the browser

Question. A context manager of OpenTelemetry keeps the active span through asynchronous code. In the browser, zone.js and async-browser-context do this work on the main thread. They wrap each promise reaction, each timer and each event listener.

How much main-thread time does each one cost? Does it change the values that the monitors of lag measure, or only the cost? Which asynchronous code keeps the span?

The answer is necessary for two decisions: the default context manager of otel-ts, and an add-on of lag that uses async-browser-context. In Firefox and Safari, no Long Animation Frames entry names the script of a long task. An async context could name the operation that caused the lag.

Method. The package @lag/experiments builds one page with Vite in four setups. Only the setup module and the options of the build are different:

  • A. No async context. The option of otel-ts is contextManager: "stack". The StackContextManager patches nothing. The build replaces @opentelemetry/context-zone with a module without zone.js.
  • B. Zone.js. The option of otel-ts is contextManager: "zone", the default of otel-ts at this time. The zone.js library patches Promise, the timers and the event listeners.
  • C. AsyncBrowserContext. The page uses the npm package async-browser-context 0.2.0. Its Vite plugin transforms all modules, also the dependencies. The page gives AsyncContextManager of async-browser-context/opentelemetry to otel-ts. The build also replaces @opentelemetry/context-zone, because the library must not operate together with zone.js.
  • D. stack, zone.js loaded. The option of otel-ts is contextManager: "stack", with otel-ts as the package is. The package imports @opentelemetry/context-zone for each value of the option, and that module loads zone.js. Thus zone.js patches the page also in this setup.

The plugin of setup C adds an import of async-browser-context/runtime to each module that it transforms. With pnpm, the folders of lag and otel-ts cannot resolve that import. Thus the build of setup C sets the Vite option resolve.dedupe: ["async-browser-context"].

The page starts otel-ts with tracing, which registers the context manager. The instrumentations, the metrics, the logs and Faro of otel-ts are off. The spans of the page do not record, thus nothing goes to an exporter. The runner counted 0 requests to the OTLP path of the page. The monitors of setupAllMonitors, with the worker of lag, record into a meter in memory.

The runner opens a new browser for each page run. A page run has these phases:

  1. The setup alone, idle for 10 s.
  2. The setup with the monitors: 6 s to settle, then 10 s idle. Chromium gives the main-thread time of the renderer through CDP (Performance.getMetrics), as in the overhead benchmark.
  3. MacrotaskLag and SchedulingFairnessMonitor with an interval of 200 ms, for 10 s. The monitors of the setup sample each 5 s, thus these probes give more samples.
  4. Five scripted clicks with a click handler of 100 ms. Then five setTimeout(0) tasks of 150 ms.
  5. The workloads, with the monitors stopped: one run to warm up, then five measured runs.
  6. The context check.

The workloads are fixed amounts of asynchronous work:

  • promise-chain: a chain of 50,000 then calls (promiseChain of @lag/load).
  • await-loop: one async function with 50,000 await expressions.
  • async-calls: 5,000 async functions at the same time, with 10 await expressions each.
  • microtasks: 50,000 queueMicrotask callbacks, one after the other (microtaskFlood of @lag/load).
  • timers: 2,000 setTimeout(0) timers at the same time.
  • events: 50,000 calls of dispatchEvent, with one listener.
  • fetch: 100 fetches of a small JSON file from the local server, 10 at the same time.
  • operations: 200 operations at the same time, as in an application. Each one does a fetch, reads the JSON body, waits for a setTimeout(0), dispatches 10 events and does 10 await expressions.

A round does one page run of each setup. Each round has a different order: A B C D, B C D A, C D A B, D A B C and D C B A. The load of the machine can change during a measurement, thus a fixed order can make one setup look slower (performance of async-browser-context). A table cell gives the median of 5 rounds and, in parentheses, the lowest and the highest round. A factor compares a setup with setup A of the same round.

The measurement of 2026-10-12 used Chromium 145.0.7632.6, Firefox 146.0.1 and WebKit 26.0 of Playwright 1.58.2, with 5 rounds in each engine. Chromium operated in the new headless mode. Firefox and WebKit have no CDP, thus they give no main-thread time and no idle cost. They also have no Long Animation Frames entries. The packages were otel-ts 0.0.1 (commit 92cd393), @opentelemetry/context-zone 2.6.1, zone.js 0.16.1, async-browser-context 0.2.0 and Vite 7.3.1. The results file has the data of all 60 page runs (local-experiments.e8.json).

The load of the machine. The machine was a computer with Windows 11, an AMD Ryzen AI 7 PRO 350 (16 logical cores) and 28 GiB of memory, on AC power. Other programs used the CPU during the measurement: WSL and Docker (approximately 12% of the CPU), a type checker, Microsoft Defender and VS Code. The runner records the load of the whole machine during each page run, also the browser of the run:

EngineLoad of the machine during a page run: median of the 20 page runs (lowest to highest)
Chromium59% (33% to 98%)
Firefox94% (49% to 100%)
WebKit85% (45% to 100%)

Thus the ranges of this measurement are wide. Only two types of results are conclusions. The first type does not depend on time. The second type is a factor that is on the same side of 1 in each round. The section E8: the conclusions gives them.

Results: the cost on an idle page, Chromium. The values are the main-thread time of each second, in ms. The difference compares the setup with setup A of the same round.

SetupSetup alone: task timeWith the monitors: task timeWith the monitors: script timeWith the monitors: task time, difference to A
A0.137.9 (31.2 to 45.6)15.9 (13.0 to 19.6)–
B0.149.3 (41.7 to 66.6)25.3 (20.4 to 31.0)+18.0 (−2.3 to 33.2)
C0.156.6 (29.3 to 62.8)22.5 (12.7 to 26.1)+11.0 (−8.6 to 29.4)
D0.1 (0.1 to 0.2)51.5 (38.8 to 61.0)26.0 (20.1 to 32.8)+18.7 (−1.8 to 23.1)

Each difference has a range from below 0 to more than 20 ms. The differences followed the load. In two rounds, the load of setups A and C was similar (39% to 47%). In these rounds, setup C used 29.3 ms and 32.0 ms, and setup A used 31.2 ms and 40.6 ms. Thus this table does not measure the cost of the setups.

A measurement of 2026-10-11 was quieter, with a load of 25% to 41%. It used only Chromium and async-browser-context 0.1.1. Its idle differences were +5.4 ms for setup B (−1.3 to 6.3), +1.6 ms for setup C (−0.7 to 4.0) and +5.2 ms for setup D (1.9 to 8.2). The monitors alone used 30.5 ms each second. Version 0.2.0 adds a check for hooks to each callback, thus its value can be a little higher. These differences are the best estimate of this experiment for the idle cost.

Results: the workloads, version 0.2.0. These tables come from the measurement of 2026-10-12, thus setup C used async-browser-context 0.2.0. Version 0.2.2 changed the cost of await (refer to version 0.2.2). Each factor is the time of the setup divided by the time of setup A in the same round. The first table gives the main-thread time in Chromium (CDP TaskDuration). The other tables give the total time.

Workload, ChromiumA, main-thread time (ms)B / AC / AD / A
promise-chain14.4 (5.8 to 15.5)×8.49 (4.54 to 11.44)×0.47 (0.33 to 1.21)×6.03 (5.35 to 9.56)
await-loop5.3 (2.6 to 7.3)×0.78 (0.39 to 1.24)×1.29 (1.12 to 2.99)×0.63 (0.47 to 0.82)
async-calls7.2 (3.6 to 8.1)×1.89 (1.09 to 3.24)×1.76 (1.21 to 2.82)×1.49 (1.27 to 2.61)
microtasks54.3 (29.9 to 79.8)×0.57 (0.29 to 0.68)×1.34 (0.76 to 2.49)×0.55 (0.41 to 0.84)
timers10.5 (4.9 to 15.8)×2.11 (1.03 to 2.96)×1.05 (0.61 to 2.09)×2.06 (1.25 to 3.47)
events66.2 (42.4 to 84.8)×1.07 (0.69 to 1.41)×1.09 (0.62 to 1.50)×1.21 (0.74 to 1.46)
fetch57.2 (47.6 to 102.3)×1.01 (0.53 to 1.74)×1.07 (0.56 to 2.35)×1.15 (0.68 to 1.95)
operations139.6 (90.9 to 222.0)×1.20 (0.53 to 1.62)×1.15 (0.84 to 2.07)×1.04 (0.83 to 1.59)
Workload, ChromiumA, total time (ms)B / AC / AD / A
promise-chain13.6 (5.3 to 14.6)×9.10 (4.83 to 12.30)×0.41 (0.30 to 1.11)×6.48 (5.65 to 10.26)
await-loop4.4 (2.1 to 6.5)×0.66 (0.43 to 1.19)×1.34 (1.10 to 3.33)×0.59 (0.42 to 0.81)
async-calls6.2 (3.2 to 7.2)×1.99 (1.19 to 3.57)×1.79 (1.25 to 2.91)×1.54 (1.42 to 2.82)
microtasks52.1 (28.6 to 75.5)×0.59 (0.29 to 0.75)×1.37 (0.63 to 2.05)×0.58 (0.40 to 0.86)
timers12.4 (5.6 to 17.8)×2.03 (0.94 to 2.79)×1.07 (0.61 to 2.13)×1.90 (1.15 to 3.29)
events61.0 (39.5 to 74.5)×1.05 (0.72 to 1.40)×1.09 (0.64 to 1.50)×1.21 (0.79 to 1.45)
fetch196.4 (161.9 to 476.6)×0.86 (0.32 to 2.38)×1.15 (0.39 to 2.39)×0.97 (0.40 to 1.67)
operations493.9 (302.1 to 1773.5)×0.98 (0.16 to 2.03)×0.81 (0.29 to 2.58)×0.91 (0.31 to 1.35)
Workload, FirefoxA, total time (ms)B / AC / AD / A
promise-chain429.0 (206.0 to 521.0)×2.62 (1.39 to 7.91)×1.02 (0.79 to 1.68)×2.66 (1.79 to 5.72)
await-loop19.0 (12.0 to 38.0)×0.87 (0.48 to 1.50)×84.11 (79.16 to 140.33)×1.08 (0.58 to 1.42)
async-calls1538.0 (939.0 to 2018.0)×1.33 (0.79 to 2.01)×1.25 (0.51 to 3.29)×1.29 (0.92 to 1.84)
microtasks255.0 (125.0 to 318.0)×14.42 (6.04 to 18.90)×3.32 (1.44 to 4.75)×14.24 (7.87 to 17.63)
timers99.0 (46.0 to 133.0)×0.50 (0.19 to 2.08)×2.03 (0.55 to 4.50)×0.41 (0.32 to 0.59)
events191.0 (124.0 to 294.0)×0.66 (0.37 to 3.48)×0.84 (0.51 to 1.57)×0.62 (0.46 to 0.69)
fetch1333.0 (345.0 to 2914.0)×0.62 (0.18 to 1.01)×0.65 (0.17 to 2.08)×0.43 (0.11 to 1.00)
operations1627.0 (549.0 to 2484.0)×0.61 (0.43 to 1.18)×0.70 (0.43 to 3.66)×0.65 (0.36 to 1.49)
Workload, WebKitA, total time (ms)B / AC / AD / A
promise-chain8.0 (6.0 to 15.0)×4.63 (3.50 to 28.67)×1.63 (1.00 to 10.83)×10.71 (3.88 to 27.67)
await-loop4.0 (2.0 to 5.0)×1.50 (0.75 to 4.25)×3.00 (1.75 to 6.00)×1.67 (0.75 to 4.40)
async-calls4.0 (3.0 to 8.0)×2.50 (1.88 to 20.83)×5.50 (3.50 to 22.83)×3.83 (2.67 to 12.25)
microtasks4.0 (3.0 to 5.0)×4.33 (2.00 to 44.00)×3.60 (2.00 to 13.50)×4.33 (2.67 to 19.60)
timers179.0 (155.0 to 324.0)×1.26 (0.90 to 5.87)×1.54 (1.13 to 5.64)×1.60 (1.02 to 4.48)
events34.0 (30.0 to 64.0)×1.87 (1.08 to 4.66)×1.67 (1.16 to 4.63)×2.07 (0.97 to 6.29)
fetch170.0 (154.0 to 453.0)×1.31 (0.81 to 1.99)×1.62 (0.85 to 4.30)×1.38 (0.96 to 3.32)
operations287.0 (215.0 to 784.0)×1.02 (0.55 to 2.28)×1.45 (0.59 to 2.75)×1.33 (1.01 to 2.95)

In WebKit, the first four workloads took 3 ms to 15 ms in setup A, and the clock of WebKit has a resolution of 1 ms. Thus their factors are coarse.

Total time of the workloads, compared with setup A

B. Zone.jsC. AsyncBrowserContextD. stack, zone.js loaded
ChromiumFirefoxWebKitpromise-chainawait-loopasync-callsmicrotaskstimerseventsfetchoperationspromise-chainawait-loopasync-callsmicrotaskstimerseventsfetchoperationspromise-chainawait-loopasync-callsmicrotaskstimerseventsfetchoperations×0.2×1×2×10×20×100Total time of the workload / total time in setup A →
Show the data as a table
Total time of each workload divided by the total time in setup A of the same round: the median and the range of 5 rounds
EngineWorkloadSetupMedianLowest roundHighest round
Chromiumpromise-chainB. Zone.js×9.1×4.83×12.3
Chromiumawait-loopB. Zone.js×0.66×0.43×1.19
Chromiumasync-callsB. Zone.js×1.99×1.19×3.57
ChromiummicrotasksB. Zone.js×0.59×0.29×0.75
ChromiumtimersB. Zone.js×2.03×0.94×2.79
ChromiumeventsB. Zone.js×1.05×0.72×1.4
ChromiumfetchB. Zone.js×0.86×0.32×2.38
ChromiumoperationsB. Zone.js×0.98×0.16×2.03
Chromiumpromise-chainC. AsyncBrowserContext×0.41×0.3×1.11
Chromiumawait-loopC. AsyncBrowserContext×1.34×1.1×3.33
Chromiumasync-callsC. AsyncBrowserContext×1.79×1.25×2.91
ChromiummicrotasksC. AsyncBrowserContext×1.37×0.63×2.05
ChromiumtimersC. AsyncBrowserContext×1.07×0.61×2.13
ChromiumeventsC. AsyncBrowserContext×1.09×0.64×1.5
ChromiumfetchC. AsyncBrowserContext×1.15×0.39×2.39
ChromiumoperationsC. AsyncBrowserContext×0.81×0.29×2.58
Chromiumpromise-chainD. stack, zone.js loaded×6.48×5.65×10.26
Chromiumawait-loopD. stack, zone.js loaded×0.59×0.42×0.81
Chromiumasync-callsD. stack, zone.js loaded×1.54×1.42×2.82
ChromiummicrotasksD. stack, zone.js loaded×0.58×0.4×0.86
ChromiumtimersD. stack, zone.js loaded×1.9×1.15×3.29
ChromiumeventsD. stack, zone.js loaded×1.21×0.79×1.45
ChromiumfetchD. stack, zone.js loaded×0.97×0.4×1.67
ChromiumoperationsD. stack, zone.js loaded×0.91×0.31×1.35
Firefoxpromise-chainB. Zone.js×2.62×1.39×7.91
Firefoxawait-loopB. Zone.js×0.87×0.48×1.5
Firefoxasync-callsB. Zone.js×1.33×0.79×2.01
FirefoxmicrotasksB. Zone.js×14.42×6.04×18.9
FirefoxtimersB. Zone.js×0.5×0.19×2.08
FirefoxeventsB. Zone.js×0.66×0.37×3.48
FirefoxfetchB. Zone.js×0.62×0.18×1.01
FirefoxoperationsB. Zone.js×0.61×0.43×1.18
Firefoxpromise-chainC. AsyncBrowserContext×1.02×0.79×1.68
Firefoxawait-loopC. AsyncBrowserContext×84.11×79.16×140.33
Firefoxasync-callsC. AsyncBrowserContext×1.25×0.51×3.29
FirefoxmicrotasksC. AsyncBrowserContext×3.32×1.44×4.75
FirefoxtimersC. AsyncBrowserContext×2.03×0.55×4.5
FirefoxeventsC. AsyncBrowserContext×0.84×0.51×1.57
FirefoxfetchC. AsyncBrowserContext×0.65×0.17×2.08
FirefoxoperationsC. AsyncBrowserContext×0.7×0.43×3.66
Firefoxpromise-chainD. stack, zone.js loaded×2.66×1.79×5.72
Firefoxawait-loopD. stack, zone.js loaded×1.08×0.58×1.42
Firefoxasync-callsD. stack, zone.js loaded×1.29×0.92×1.84
FirefoxmicrotasksD. stack, zone.js loaded×14.24×7.87×17.63
FirefoxtimersD. stack, zone.js loaded×0.41×0.32×0.59
FirefoxeventsD. stack, zone.js loaded×0.62×0.46×0.69
FirefoxfetchD. stack, zone.js loaded×0.43×0.11×1
FirefoxoperationsD. stack, zone.js loaded×0.65×0.36×1.49
WebKitpromise-chainB. Zone.js×4.63×3.5×28.67
WebKitawait-loopB. Zone.js×1.5×0.75×4.25
WebKitasync-callsB. Zone.js×2.5×1.88×20.83
WebKitmicrotasksB. Zone.js×4.33×2×44
WebKittimersB. Zone.js×1.26×0.9×5.87
WebKiteventsB. Zone.js×1.87×1.08×4.66
WebKitfetchB. Zone.js×1.31×0.81×1.99
WebKitoperationsB. Zone.js×1.02×0.55×2.28
WebKitpromise-chainC. AsyncBrowserContext×1.63×1×10.83
WebKitawait-loopC. AsyncBrowserContext×3×1.75×6
WebKitasync-callsC. AsyncBrowserContext×5.5×3.5×22.83
WebKitmicrotasksC. AsyncBrowserContext×3.6×2×13.5
WebKittimersC. AsyncBrowserContext×1.54×1.13×5.64
WebKiteventsC. AsyncBrowserContext×1.67×1.16×4.63
WebKitfetchC. AsyncBrowserContext×1.62×0.85×4.3
WebKitoperationsC. AsyncBrowserContext×1.45×0.59×2.75
WebKitpromise-chainD. stack, zone.js loaded×10.71×3.88×27.67
WebKitawait-loopD. stack, zone.js loaded×1.67×0.75×4.4
WebKitasync-callsD. stack, zone.js loaded×3.83×2.67×12.25
WebKitmicrotasksD. stack, zone.js loaded×4.33×2.67×19.6
WebKittimersD. stack, zone.js loaded×1.6×1.02×4.48
WebKiteventsD. stack, zone.js loaded×2.07×0.97×6.29
WebKitfetchD. stack, zone.js loaded×1.38×0.96×3.32
WebKitoperationsD. stack, zone.js loaded×1.33×1.01×2.95
Experiment E8, 2026-10-12, Windows 11, 5 rounds in each engine, on a busy machine. Setup C used async-browser-context 0.2.0. The x axis is logarithmic. The vertical rule at 1 is the time of setup A.

Results: the await step in Firefox, version 0.2.0. In Firefox, the workload await-loop of setup C took 84 times the time of setup A, from 79 to 140 times in the 5 rounds. A short probe on the same machine found the cause (pnpm --filter @lag/experiments e8:await-probe). It measured 50,000 sequential steps in each form, in turns in one browser, and it gives the median of 7 measurements. A factor compares the form with the native form without a library. This table is the probe of 2026-10-12, with version 0.2.0:

Form, time of one stepChromiumFirefoxFirefox, javascript.options.asyncstack: false
Native await0.05 µs0.20 µs0.20 µs
A generator and a native then for each step, without a library0.06 µs (×1.3)9.36 µs (×47)3.12 µs (×16)
Transformed await of async-browser-context0.09 µs (×1.8)13.78 µs (×69)3.40 µs (×17)
Transformed await, with a hook that does nothing0.14 µs (×2.9)17.14 µs (×86)4.82 µs (×24)
queueMicrotask chain, without a library0.57 µs1.94 µs0.66 µs
queueMicrotask chain, async-browser-context0.57 µs (×1.0)4.42 µs (×2.3)1.06 µs (×1.6)
queueMicrotask chain, zone.js0.45 µs (×0.8)6.88 µs (×3.5)2.18 µs (×3.3)

The plugin changes each await into a step of a generator, and the runtime starts the next step with a native then. A native await needs no then in JavaScript. Firefox makes the promise reaction of such a step slow.

The generator without the library was slow in the same way. It took 47 times the time of a native await, and the transformed await took 69 times. Thus the cause is a slow path of the engine for such a step. Version 0.2.2 does not use that path (version 0.2.2).

Under Playwright, Firefox also records an async stack for each promise reaction. Without async stacks, a transformed await took 17 times the time of a native await, and 24 times with a hook. With async stacks, it took 69 to 86 times.

The setting javascript.options.asyncstack_capture_debuggee_only: true records async stacks only while a debugger observes the page. With that setting, the cost stayed the same, probably because Playwright controls the page as a debugger. The probe did not examine Firefox without automation. A page with open developer tools probably has the same cost.

For the microtasks of zone.js in Firefox, the probe gave 3.5 times the time, with and without async stacks. The full measurement gave 14 times, with a load of approximately 95%. Thus the direction is certain, but the size is not.

Results: the values of the monitors. The tables give the readings of the monitors in each setup:

Reading, ChromiumABCD
DriftLag, idle median (ms)0.2 (0.0 to 18.4)3.5 (0.2 to 18.9)11.5 (0.2 to 23.2)0.0 (0.0 to 10.5)
DriftLag, idle p95 (ms)2.9 (2.6 to 47.7)42.2 (3.4 to 71.8)50.1 (2.7 to 56.5)3.0 (2.2 to 39.0)
MacrotaskLag, median (ms)0.10.10.10.1
SchedulingFairness, microtask, median (ms)0.00.00.00.0
SchedulingFairness, setTimeout(0), median (ms)0.1 (0.0 to 0.1)0.10.1 (0.0 to 0.1)0.1
SchedulingFairness, message, median (ms)0.10.10.10.1
INP of lag, 5 clicks with a 100 ms handler (ms)128 (128 to 136)128 (120 to 136)128 (120 to 128)128 (120 to 136)
Duration of one click interaction, median (ms)112 (112 to 120)112 (112 to 120)112112 (112 to 120)
LoAF blocking of a 150 ms task, median (ms)100.2 (100.2 to 100.4)100.3 (100.2 to 100.5)100.2 (100.2 to 100.4)100.3 (100.2 to 100.3)
Reading, FirefoxABCD
DriftLag, idle median (ms)0.6 (0.1 to 51.1)1.5 (0.0 to 7.7)1.5 (0.4 to 18.6)1.2 (0.0 to 6.8)
DriftLag, idle p95 (ms)19.1 (9.8 to 110.2)11.8 (8.0 to 68.7)21.4 (8.5 to 55.8)15.3 (9.7 to 59.5)
MacrotaskLag, median (ms)0.00.0 (0.0 to 1.0)0.00.0
SchedulingFairness, all three medians (ms)0.00.00.00.0 (0.0 to 1.0)
INP of lag, 5 clicks with a 100 ms handler (ms)120 (104 to 128)112 (104 to 144)112 (104 to 120)120 (104 to 176)
Duration of one click interaction, median (ms)112 (104 to 120)104 (104 to 128)104104 (104 to 128)
Reading, WebKitABCD
DriftLag, idle median (ms)0.0 (0.0 to 1.5)0.0 (0.0 to 5.9)0.0 (0.0 to 1.8)0.0 (0.0 to 2.0)
DriftLag, idle p95 (ms)1.6 (1.1 to 7.3)1.8 (1.5 to 76.5)2.0 (1.2 to 6.3)2.8 (1.7 to 18.0)
MacrotaskLag, median (ms)14 (12 to 14)16 (15 to 16)14 (10 to 15)15 (15 to 16)
SchedulingFairness, microtask, median (ms)0.00.00.00.0
SchedulingFairness, setTimeout(0), median (ms)14 (13 to 14)15 (14 to 16)14 (10 to 14)15 (15 to 16)
SchedulingFairness, message, median (ms)14 (13 to 14)16 (15 to 17)14 (13 to 15)16 (15 to 16)
INP of lag, 5 clicks with a 100 ms handler (ms)112 (104 to 136)120 (104 to 192)136 (104 to 176)112 (104 to 144)
Duration of one click interaction, median (ms)104 (104 to 128)112 (104 to 144)120 (104 to 144)104 (104 to 136)

In Chromium, the idle values of DriftLag increased in each setup in the rounds with a high load. Thus they show the load of the machine, not the setup. In Chromium and Firefox, the other readings had no difference between the setups that was the same in each round. The quiet measurement of 2026-10-11 gave the same result for Chromium.

WebKit had two differences:

  • The task latencies with zone.js. In WebKit for Windows, a message waits for the timer tick of the system, thus the latencies are approximately 14 ms (E5). In setups B and D, the medians of MacrotaskLag and SchedulingFairnessMonitor were 1 ms to 4 ms longer, in each round. The comparison is with setup A of the same round. Setup C had the highest load, but no such difference. Thus the difference probably comes from zone.js, for a cause that the experiment did not find.
  • The clicks with async-browser-context. In each round, the click interactions of setup C took as long as in setup A or longer, by up to 32 ms. The load during setup C was also the highest (a median of 98%). Thus the experiment cannot separate the setup from the load.

Results: the Long Animation Frames entries. In each setup, the invoker of the longest script of the 150 ms task was TimerHandler:setTimeout. The function name was different:

  • Setup A: fixedBlockingTask, the function of the page.
  • Setups B and D: no function name. The function that the browser starts is a wrapper of zone.js.
  • Setup C: asyncBrowserContextWrapper, the wrapper of async-browser-context 0.2.0.

The entry gives the function that the browser starts, thus also its URL and its position in the source are those of the wrapper. The page was one bundle, thus the URL was the bundle of the page in each setup.

Results: the active span. Each case makes a span active, starts asynchronous work, and examines the active span when the work continues. The results were the same in Chromium, Firefox and WebKit, in each round:

CaseABCD
Synchronous code (control)YesYesYesYes
Promise.then callbackNoYesYesNo
After awaitNoNoYesNo
setTimeout callbackNoYesYesNo
Event listener, the browser dispatches the event (message)NoYesYesNo
Event listener, a dispatch in the root context (C13: the context of the registration)NoYesYesNo
fetch().then() callbackNoYesYesNo
After await fetch()NoNoYesNo
No active span after the cases (control)YesYesYesYes

In setup C, a listener of an event that code dispatched in the root context got the span of the addEventListener() call. The library documents this case (rule C13). A listener gets the context of the dispatch, but for a dispatch in the root context it gets the context of the registration. Code that must give no span dispatches the event in context.with(ROOT_CONTEXT, …).

Results: the bundle size. The values come from minified builds of the same page, without the worker of lag. gzip used the default level of zlib (6).

SetupJavaScript of the page (KiB)gzip (KiB)gzip, difference to A (KiB)Contains zone.jsContains async-browser-context
A386.2118.3–NoNo
B422.7131.2+12.9YesNo
C404.9124.0+5.7NoYes
D422.7131.2+12.9YesNo

E8: version 0.2.2

Version 0.2.2 of async-browser-context changed the coroutine. In this version, a native async function drives each transformed async function, and its native await waits for each step. Thus no then callback of JavaScript remains for each step. The full measurement did not use version 0.2.2, but the await probe did. The probe also operated in WebKit, and it had a second form: the await of a resolved promise.

During the probe, another program used all the CPUs of the machine (a load of 100%). The probe compares the forms in turns in one browser, thus the load changes the factors less than the times. A factor compares the form with the native form of the same type, without a library.

Form, time of one stepChromiumFirefoxFirefox, asyncstack: falseWebKit
Native await of a value (await null)0.07 µs0.32 µs0.38 µs0.10 µs
Transformed await of a value0.13 µs (×1.9)0.58 µs (×1.8)0.74 µs (×1.9)0.18 µs (×1.8)
Transformed await of a value, with a hook that does nothing0.26 µs (×3.8)0.84 µs (×2.6)0.84 µs (×2.2)0.30 µs (×3.0)
Native await of a resolved promise0.05 µs0.48 µs0.48 µs0.10 µs
Native await of a resolved promise, with the patches of async-browser-context0.05 µs (×0.9)2.70 µs (×5.6)2.38 µs (×5.0)0.10 µs (×1.0)
Transformed await of a resolved promise0.12 µs (×2.1)2.80 µs (×5.8)2.64 µs (×5.5)0.20 µs (×2.0)
Native await of a resolved promise of zone.js1.87 µs (×35)111 µs (×232)15.3 µs (×32)2.50 µs (×25)
queueMicrotask chain, async-browser-context×1.1×1.5×1.2×3.0
queueMicrotask chain, zone.js×0.8×10.8×4.1×6.8

The results:

  • The fix. In Firefox, a transformed await of a value took 0.58 µs, and 13.8 µs with version 0.2.0. Thus the factor went from 69 to 1.8. In Chromium and WebKit, the factor stayed near 2.
  • The cost that remains in Firefox. The runtime patches Promise.prototype.then, and that patch turns off the fast path of Firefox for an await of a promise. In the probe, each await of a resolved promise took approximately 2 µs more (0.48 µs and 2.70 µs). The cost is the same in code that the plugin does not transform, because the patch is global. An await of a value is not affected. Chromium and WebKit had no such cost.
  • The size of that cost. The probe operated on a machine with a load of 100%. The benchmark of the library gives approximately 0.8 µs for each await of a promise in Firefox.
  • zone.js. With zone.js, the global Promise is the promise of zone.js, thus each await of a promise starts a then of zone.js. In Firefox, such an await took 15 µs without async stacks, and 111 µs with them. It took 1.9 µs in Chromium and 2.5 µs in WebKit. Thus zone.js has the same type of cost in each engine, and more of it.
  • The microtasks of zone.js. In Firefox, the chain took 10.8 times the time in this probe, and 3.5 times in the probe with version 0.2.0. Thus the factor depends on the load.

E8: the conclusions

These results do not depend on time, thus the load does not change them:

  • What each setup keeps. Only setup C kept the span in all cases, in the three engines. Setup B lost it after each native await. A native await does not use code that zone.js can patch. Setups A and D kept the span only in synchronous code.
  • Setup D. The option "stack" loads zone.js, because otel-ts imports it for each option. Thus a user of "stack" pays for zone.js and gets no context.
  • The bundle size. The zone.js library adds 12.9 KiB of gzip, and async-browser-context 0.2.0 adds 5.7 KiB.
  • The attribution. Both libraries replace the function that the browser starts. Thus a Long Animation Frames entry names the wrapper, or no function, in place of the function of the page.

These factors were on the same side of 1 in each round:

  • The await step in Firefox, version 0.2.0. The transformed await took 84 times the time of a native await (79 to 140). The probe found the cause: Firefox makes the then of each step slow, and async stacks make it slower. Version 0.2.2 removes most of this cost: in the probe, the factor is 1.8.
  • Promise chains with zone.js. In setups B and D, the promise chain took 6 to 9 times the time in Chromium. It took 2.6 times the time in Firefox, and 5 to 11 times in WebKit. For comparison, the factors of setup C were 0.41 in Chromium, 1.02 in Firefox and 1.63 in WebKit.
  • Microtasks with zone.js in Firefox. In setups B and D, they took 14 times the time (6 to 19). The probe gave 3.5 times. In Chromium, zone.js made them faster (0.57 times), because it starts many of them in one native microtask.
  • Async functions. In Chromium, async-calls took 1.8 to 2.0 times the time in setups B and C. In setup C, await-loop took 1.3 times the time. The probe gave 1.8 times for one transformed await step in Chromium.
  • The task latencies of WebKit with zone.js. In setups B and D, MacrotaskLag and SchedulingFairnessMonitor gave 1 ms to 4 ms more than in setup A of the same round.

The other results are not conclusions. The idle cost of this measurement followed the load. Thus the quiet measurement of 2026-10-11 is the estimate. It gave +5.4 ms each second for zone.js and +1.6 ms for async-browser-context 0.1.1, with 30.5 ms for the monitors alone. The workloads events, fetch and operations had ranges on the two sides of 1 in most engines and setups. Setup C did not change a value of the monitors in a way that the load cannot explain.

One result was not expected. In Chromium, the promise chain was faster in setup C than in setup A in 4 of 5 rounds (0.41 times the time). The experiment did not find the cause.

Recommendation. The owner decided two changes. otel-ts will use the runtime of async-browser-context as its default context manager, and zone.js becomes an option. An application adds the plugin of the library when it needs the span after await. E8 gives this data for the decision:

  • The runtime in place of zone.js. The data supports it. The runtime kept the span in each case where zone.js kept it, and it costs less:

    • Idle page: +1.6 ms each second, against +5.4 ms for zone.js (the quiet measurement).
    • Promise chains: up to 1.6 times the time, against 2.6 to 11 times.
    • Bundle: 5.7 KiB, against 12.9 KiB.

    E8 measured the runtime together with the plugin. The cases without await use only the patches of the runtime. The runtime has one cost on native code. In Firefox, each await of a promise takes approximately 0.8 µs to 2.2 µs more (version 0.2.2). With zone.js, such an await takes 15 µs or more in Firefox.

  • zone.js as an option. The data supports it, because zone.js does not keep the span after a native await. Setup D shows that each user of otel-ts pays for it at this time. For the option, otel-ts must load zone.js only for "zone". In the version that E8 measured, the static import of @opentelemetry/context-zone loads it for each option. Since version 0.1.0 (commit a291331), otel-ts loads zone.js only through the entry @mark1russell7/otel-ts/zone, and its main entry uses async-browser-context.

  • The cost of the plugin for await. Use version 0.2.2 or later. With version 0.2.2, a transformed await of a value costs approximately 2 times a native await in Chromium, Firefox and WebKit (0.13 µs, 0.58 µs and 0.18 µs in the probe). With version 0.2.0, it cost 69 to 84 times in Firefox.

  • The cost of the patch of then in Firefox. In Firefox, each await of a promise costs approximately 0.8 µs to 2.2 µs more, in transformed code and in other code. Chromium and WebKit have no such cost. The patch of Promise.prototype.then causes it. The runtime installs that patch for all code, thus each page that loads the runtime pays it. The zone.js library has more of the same type of cost, with 15 µs to 111 µs for each await of one of its promises in Firefox.

  • A page without the cost. A page that must not pay the cost of the patch loads no context library. The entry @mark1russell7/otel-ts/core of otel-ts 0.1.0 loads none. Then the span stays only in synchronous code, as in setup A.

  • The use of the plugin. The plugin is necessary only for the code that needs the span after await. With version 0.2.2, its own cost is small, thus an application can also transform its hot loops. The options include and exclude of the plugin only select the code that the plugin transforms. That code keeps the span after await, and it pays the cost of a transformed step. The options do not remove the cost of the patch of then, because that patch is global.

  • The documentation of otel-ts. It must give the cost of an await of a promise in Firefox, for the runtime and for zone.js.

  • The attribution of lag. With the runtime as the default of otel-ts, the Long Animation Frames entries of each page with otel-ts name asyncBrowserContextWrapper in Chromium. Thus lag loses the name and the source position of the script that caused a long frame.

  • The add-on of lag. Version 0.2.0 makes it possible. addCallbackHook starts the hook before and after each callback. The hook gets the real function, the API that started it (for example setTimeout, Promise.then or await) and the context of the callback. Thus the add-on can give the attribution back in Chromium. It can also give a first attribution in Firefox and Safari.

  • The cost of the hook. The hook operates for each callback. With version 0.2.2, a hook that did nothing made each transformed await step 1.1 to 2 times longer, or 0.1 µs to 0.3 µs. Thus the hook of the add-on must do little work. For example, it reads the clock at the start and at the end, and it records only a long callback. E8 did not measure the idle cost of the monitors with a hook.

  • The readings of the monitors. Setup C did not change a value that lag measures, in a way that the load cannot explain. The zone.js library made the task latencies of WebKit 1 ms to 4 ms longer. Thus the new default needs no change to the monitors.

Run E8 again. From the root of the repository:

pnpm experiment:e8

The command builds the workspace and the four pages, and it measures 5 rounds in Chromium, Firefox and WebKit. A full measurement takes approximately 65 minutes. It writes local-experiments.e8.json beside this page and prints the tables of this section. The options are --engines=chromium,firefox,webkit, --rounds=5, --setups=A,B,C,D and --quick. The option --quick only examines the harness.

The package @lag/experiments pins otel-ts at commit 92cd393, the version that E8 measured. From version 0.1.0, otel-ts has the entries /zone and /core, and its main entry does not accept "zone". A measurement of otel-ts 0.1.0 needs other setups. Since 2026-11-09, a pnpm override gives this pin @opentelemetry/core 2.12 in place of 2.6, for the advisory GHSA-8988-4f7v-96qf. The context managers that E8 measures are not in that package, and the measurement of 2026-10-12 was made before this change.

After a stop, --resume=<file> takes the results of a results file or of packages/experiments/dist/e8/partial.json. Then the runner measures only the missing page runs. The command pnpm --filter @lag/experiments e8:tables prints the tables from the file. The command pnpm --filter @lag/experiments e8:await-probe does the probe of the await step, in a few minutes. Close the other programs before a measurement: the load of this measurement made the idle cost useless.

Limits.

  • One machine with Windows 11, on AC power, with a high load from other programs (refer to the method). Only the results that do not depend on time, and the factors with all rounds on the same side of 1, are conclusions.
  • Safari on macOS was not available on the machine, and the WebKit build for Windows is not Safari.
  • Under Playwright, Firefox recorded async stacks, also with the setting for a debuggee only. The probe did not examine Firefox without automation. Thus the cost of an await step for the users of Firefox is probably the value without async stacks. The experiment did not measure it.
  • The best idle cost comes from the quiet measurement of 2026-10-11, with version 0.1.1 and only Chromium.
  • The full measurement used version 0.2.0. Thus the workload factors of setup C are those of version 0.2.0. Version 0.2.2 has only the probe, which operated with a load of 100% on the machine. Its times are high, and its factors are approximate.
  • The workloads do only asynchronous work, thus their factors are the largest possible factors. In an application, the network, the rendering and the other work take more time.
  • The page turned off the instrumentations of otel-ts. They have their own cost, which this experiment did not measure. With zone.js, the user-interaction instrumentation also uses zones.
  • The runner measured builds without minification, so that the Long Animation Frames entries show the function names. The bundle sizes come from minified builds.
  • Event Timing rounds a duration to 8 ms, thus a smaller difference of INP is not visible. In Chromium without cross-origin isolation, performance.now() has a resolution of 0.1 ms. In WebKit, it has a resolution of 1 ms.

E9: a cross-origin frame off the screen

Question. A document in a frame (an iframe) can be off the screen while its visibilityState stays visible. Thus the lifecycle of the page does not pause its monitors. What do the animation frames, the idle callbacks and the timers of such a frame do? Does an IntersectionObserver in the frame see the change, also while the browser does not render the frame?

Method. The runner is e9-offscreen-frame/runner/run.ts (pnpm --filter @lag/experiments e9).

A top-level page on 127.0.0.1 has a frame of 300 × 300 px from localhost, which is a different origin. The frame records each animation frame, each idle callback and a timer of 100 ms. An IntersectionObserver on its documentElement records each notification. The runner scrolls the frame off the screen for 4 s, and then back. The headless builds of Playwright operated on Windows 11, in three runs for each engine (2026-10-16).

MeasurementChromium 145Firefox 146WebKit (Playwright build 26.0)
Animation frames off the screenNone: one gap of 4000 ms to 4020 msOne each 999 ms to 1017 msNone: one gap of 4021 ms to 4036 ms
Notification "not intersecting"1 ms after the last frame16 ms to 17 ms after the last frame, before the next frame4 ms to 20 ms after the last frame
Notification "intersecting"At the change backAt the change backAt the change back
Idle callbacks off the screenNo gap of more than 200 msNo gap of more than 200 msNo requestIdleCallback
Timer of 100 ms off the screenNo gap of more than 250 msNo gap of more than 250 msGaps of 956 ms to 1074 ms

Meaning. A frame-timing monitor in such a frame records one long gap in Chromium and WebKit, and many gaps of 1 s in Firefox. The gaps are not lag. The IntersectionObserver gives the change in each engine, early enough to pause the monitor before the gap. The idle callbacks continue, thus the idle monitor needs no pause.

In the WebKit build, the timers of the frame also slow down to approximately 1 s. This is a rule of the WebKit source for each frame off the screen, thus Safari also has it (clocks and timers).

Change in the library. The frame-timing monitor pauses while its frame is off the screen, through pauseWhileHidden(monitor, { offscreen: true }) and the frameViewport of createBrowserDeps(). The timer-throttle detector counts the slow timers of the WebKit build as throttling.

Since version 0.2.2, DriftLag also pauses. Before that change, it recorded 2473 ms of lag in one window of the WebKit build. MacrotaskLag does not pause, because it starts its timeout in a message task, where the timeout is not nested. It recorded 8 ms and 9 ms in the frame off the screen.

Check in the repository. The unit tests of measurement-conditions.ts, frame-viewport.ts, instrumented/frame-timing.ts, instrumented/drift-lag.ts and browser/browser-deps.ts check the pause with a fake observer. The browser test offscreen-frame.test.ts scrolls a frame of the same origin off the screen for 6 s, with the monitors on the globals of the frame. DriftLag records no window during that time, and it records windows again after. In WebKit, the test also makes sure that a chain of 100 ms timeouts in the frame waits more than 800 ms.

In CI (pull request 52), the longest step of that chain in the frame off the screen was:

Safari 26.6.2, macOSSafari 26.5, iOS SimulatorWebKit, LinuxChromiumFirefox
1002 ms1001 ms1001 ms100 ms101 ms

Thus Safari has the rule of the WebKit source, also for a frame of the same origin. In each engine, DriftLag recorded no window off the screen, and MacrotaskLag recorded 0 ms.

Limits of the experiments

  • The local experiments used one machine with Windows 11. The Safari columns of E4, E6 and E7 come from GitHub macOS runners. The iOS column of E7 comes from the iOS Simulator of such a runner. A simulator operates on the CPU of the Mac, thus its timers and its power behavior are not those of a phone.
  • The engines were the headless builds of Playwright, except Safari. The WebKit build for Windows is not Safari on macOS.
  • The experiments did not test Safari in Low Power Mode, or Chromium on battery power. A GitHub macOS runner refuses Low Power Mode: sudo pmset -a lowpowermode 1 gives "LowPowerMode not supported on AC Power". Thus the unit test DriftLag.power.test.ts uses the timer rule of the WebKit source instead (DriftLag). On battery, Chromium uses a timer tick of 8 ms on Windows (Bruce Dawson).
  • E3 used approximately 30 idle windows for each engine.
  • E4 used a block of 2 s. The fetch probes send their requests to the test server of Vitest on the same machine, not to a remote collector.
  • E5 used one load of 4 s for each case before the change, on Windows 11. The results of the change come from three local runs, with the four browsers at the same time on the same machine. They also come from one CI run on Linux and macOS.
  • E6 and E7 used blocks of 2 s to 90 s. A real hang can be longer. E7 closed the page through Playwright or WebDriver, not through the user interface of the browser.
  • E9 used one cross-origin frame and the headless builds of Playwright, not Safari or Chrome. It did not test a same-origin frame, a frame with display: none, or a frame that the user interacted with.
  • The WebKit build for Windows makes a message wait on an idle thread (E5). In the source of WebKit, the event loop schedules each task with a timer of 0 ms (WindowEventLoop::scheduleToRun). On Windows, that timer can wait for the system timer tick (MainThreadSharedTimerWin.cpp). A newer WebKit build (Playwright 1.64) needs libGLESv2.dll from the system, and it did not start on the test machine. Thus nobody tested a newer build.
  • The browser tests of the repository operate in Chromium, Firefox, WebKit and Chrome (testing strategy). Thus they check the two cases of E1, the two properties of E3 and the behavior of E4, E6 and E7 in the four browsers. A CI job also operates them in Safari on macOS, and another in Safari in the iOS Simulator. browser-facts.test.ts checks the window case of E1.

lag: Main-thread responsiveness monitoring for browser apps, exported as OpenTelemetry metrics.

To change a page, edit its file in packages/site/content/. The writing style guide tells you how.

An AI model (Claude, from Anthropic) wrote most of the text and the code of this site and of the library, under the direction of the author. The tests and the STE linter examine them. The writing standard gives the reason for this note.