Skip to the content

Performance

The mean time of six benchmarks, with plain JavaScript, the transform only, and the library.

The benchmarks

The command pnpm bench starts each case in a separate Node.js process. Each process measures each benchmark with tinybench. A value is the mean time of one operation of the benchmark. The command does 5 rounds, with a different order of the cases in each round, and a value is the median of the rounds. The rounds decrease the effect of other work on the machine.

BenchmarkWhat it does
await loopOne async function with 10,000 await steps.
async calls10,000 async functions in sequence, each with one await.
then chainA chain of 10,000 then callbacks.
concurrent tasks1,000 async functions at the same time, each with 10 await steps, in one context.
request handlers1,000 request handlers, each in its own context, with three await steps and one read of the context.
get in nested contexts100,000 reads with get(), 5 contexts deep.

The cases

CaseWhat it measures
Plain JavaScriptThe same code without the library. A Variable class without propagation gives the same API.
Transform onlyThe Babel preset with a plain coroutine. This case shows the cost of the transform without the cost of the context.
LibraryThe Babel preset and the browser runtime.

The tools wrote this data at 23 Nov 2026, 11:15 UTC.

Node.js v24.22.3, Linux 7.0.0-1020-azure, AMD EPYC 9V74 80-Core Processor. The values come from CI run 45162855713 of 2026-11-23.

The mean time of each benchmark

Plain JavaScriptTransform onlyLibrary
await loopasync callsthen chainconcurrent tasksrequest handlersget in nested contexts0.00.51.01.52.0Mean time (ms) →1×1.35×1.63×1×1.71×2.51×1×0.99×1.82×1×1.38×2.23×1×1.24×2.27×1×1×3.51×
Show the data as a table
BenchmarkCaseMean timeFactor
await loopPlain JavaScript0.44 ms1×
await loopTransform only0.59 ms1.35×
await loopLibrary0.71 ms1.63×
async callsPlain JavaScript0.87 ms1×
async callsTransform only1.5 ms1.71×
async callsLibrary2.2 ms2.51×
then chainPlain JavaScript0.27 ms1×
then chainTransform only0.27 ms0.99×
then chainLibrary0.49 ms1.82×
concurrent tasksPlain JavaScript0.6 ms1×
concurrent tasksTransform only0.82 ms1.38×
concurrent tasksLibrary1.3 ms2.23×
request handlersPlain JavaScript0.49 ms1×
request handlersTransform only0.61 ms1.24×
request handlersLibrary1.1 ms2.27×
get in nested contextsPlain JavaScript0.19 ms1×
get in nested contextsTransform only0.19 ms1×
get in nested contextsLibrary0.67 ms3.51×

What the results tell

  • The transform. Each async function of transformed code is a generator that the coroutine operates. This costs more than a native async function. The number of microtask steps of each await does not change.
  • The context. Each then callback and each step of the coroutine sets the context and sets it again after the step. Each then call makes two small wrappers.
  • get(). One read takes only some nanoseconds, and the home page shows the value of the last run. The plain case reads one field, so the factor is large, but the time is small.

Note

The values are microbenchmarks. The benchmarks do no other work, so the factors are the largest possible factors. Measure your own application before and after you add the library.

Size

The command pnpm bench:size builds minified bundles with Vite, and measures them with gzip and brotli. Vite builds each bundle as an application, because a library build of Vite keeps the white space. The bundle of the runtime keeps all exports of async-browser-context and async-browser-context/runtime. The results go to bench/results/size.json.

The tools wrote this data at 23 Nov 2026, 11:15 UTC.

Vite 8.3.8. The values come from CI run 45162855713 of 2026-11-23.

CodeMinifiedgzipbrotli
The runtime: the classes, the patches and the runtime of the transform22.6 kB7.4 kB6.7 kB
zone.js 0.16.3, for comparison34.7 kB11.8 kB10.7 kB

The transform also makes the code of the application larger. The command builds each package of a set of npm packages four times. Each bundle keeps all exports of the package, and does not contain the runtime. The values are gzip sizes.

The tools wrote this data at 23 Nov 2026, 11:15 UTC.

PackageAsync functionsWithout the transformWith the Vite pluginWith names: falseTarget ES2016, no plugin
react-dom 19.3.0067.6 kB67.6 kB (+0%)67.6 kB (+0%)67.7 kB (+0%)
@tanstack/query-core 5.104.2811.4 kB11.9 kB (+5.1%)11.9 kB (+5%)14.5 kB (+27.7%)
ky 2.2.02810.7 kB11.2 kB (+4.1%)11.0 kB (+2.9%)12.5 kB (+16.4%)
idb 8.0.421.5 kB1.6 kB (+7.9%)1.6 kB (+7%)2.4 kB (+64.4%)
@supabase/supabase-js 2.117.335856.0 kB58.6 kB (+4.6%)57.6 kB (+2.9%)59.5 kB (+6.3%)
openai 7.32.014580.6 kB85.6 kB (+6.2%)84.9 kB (+5.3%)88.5 kB (+9.8%)
@aws-sdk/client-s3 3.1149.021493.4 kB96.1 kB (+2.9%)95.5 kB (+2.3%)99.4 kB (+6.5%)
Example application: React DOM, TanStack Query, supabase-js and ky394144.5 kB147.9 kB (+2.4%)146.8 kB (+1.6%)151.9 kB (+5.2%)

With the Vite plugin, the API clients are 2.9 to 6.2 percent larger. The option names: false removes 0.2 to 1.8 percent of each package with async functions. The values come from CI run 45162855713 of 2026-11-23.

  • User interface code. React DOM has no async functions, so the transform does not change it. In an application, the code with async functions is usually a small part.
  • Code with much async code. The transform adds the most to API clients, as the text under the table tells. Each async function becomes a generator in a function that starts coroutine.
  • Small packages with for await. Babel adds its helper for for await to each module that has such a loop: approximately 0.5 kB with gzip. This is the cause of the large percent of TanStack Query. Since version 0.2.3, the async generators use the driver of the runtime, so the modules do not contain the async generator helper of Babel.
  • The names. The preset gives the name of each async function to the callback hooks. The option names: false removes the names.
  • The target ES2016. A compiler with this target also keeps the context through await, except rule C5 (build tools). The target also changes newer syntax, so the bundles are larger than with the preset.

Browsers

The command pnpm bench:browsers measures await and then in Chromium, Firefox and WebKit with Playwright. One run repeats a workload until a minimum time has passed, and divides the time by the number of repetitions. The text above the table gives this time, the number of steps and the number of runs. Each case has its own page, and the order of the cases changes in each run. "Babel helper" is the async transform of Babel with its own helper, without the library. Many compiled packages use such a helper.

The tools wrote this data at 23 Nov 2026, 11:16 UTC.

Each value is the time of 50,000 steps in ms, as the median of 7 runs. One run repeats the workload until at least 100 ms have passed. The values come from CI run 45162855713 of 2026-11-23.

BrowserWorkloadNativeBabel helperLibrary
Chromium 158.0.8127.18await null1.522.7
Chromium 158.0.8127.18await of a promise1.92.53
Chromium 158.0.8127.18Async generator with for await5.58.813
Chromium 158.0.8127.18then chain1.41.42.9
Firefox 159.0await null0.471782.6
Firefox 159.0await of a promise0.7514230
Firefox 159.0Async generator with for await141654475
Firefox 159.0then chain434084
WebKit 27.2await null1.22.22.4
WebKit 27.2await of a promise1.322.8
WebKit 27.2Async generator with for await4.41112
WebKit 27.2then chain1.51.67.2
  • Async generators. Since version 0.2.3, the driver of the runtime operates each async generator with a native await. Before, the helper of Babel was in each module, and each step was a then callback. With version 0.2.2, the async generator workload took 11.2 ms in Chromium, 560 ms in Firefox and 16 ms in WebKit.
  • The coroutine. Since version 0.2.2, the coroutine operates each async function with a native await. Before, each step was a then callback, as in the Babel helper. In Firefox, 50,000 awaits of null took 292 ms with version 0.2.1.
  • Firefox and the patch of then. Firefox has a fast path for await of a promise. A patch of Promise.prototype.then stops this fast path, also for code without the transform. Each await of a promise then takes approximately 0.8 µs more. zone.js also patches the promises, so it has the same cost.
  • Playwright and Firefox. Playwright controls Firefox with the debugger API. Firefox then records an async stack for each then callback. Thus, then callbacks take more time in this measurement than in a Firefox without Playwright. With the preference javascript.options.asyncstack set to false, a chain of steps in then callbacks was 7 times faster.

To change this page, edit site/content/testing/performance.mdx.

async-browser-context: AsyncLocalStorage and the TC39 AsyncContext API for browsers. The source code is on GitHub.

To change a page, edit its file in 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.