Skip to main content

Envoy performance · part 11 of 12

Arm64 atomics in Envoy main and stats cost: no resolved difference

By Otto van der Schaaf, We-Amp ·

Arm64 (AArch64) builds of Envoy main compile atomic operations as inline load-exclusive and store-exclusive loops (LL/SC), where the v1.40.2 release calls out-of-line helper routines that use the single-instruction atomics (LSE) on cores that have them. On one Arm cloud VM on Neoverse V2 cores, which have LSE, the cost of the stats in Envoy’s stats store differed by −0.09% of worker cycles per request between the two builds (95% interval −0.85 to +0.67), at 12 workers and 1,000 requests per second per worker. That difference is not resolved, and the interval excludes a difference above about 0.85% either way.

We compared the official v1.40.2 release binary with the official development image of the unreleased main branch at 5e1439980a (17 November 2026). This concerns Linux aarch64 builds; we did not examine Envoy Mobile or arm64 Mac builds. Other arm64 build comparisons are in the code-layout post.

The change comes from the build configuration. As of 3 December 2026 no Envoy release contains it, v1.40.2 included. It is on main, and since 11 November also on the release/v1.40 branch, where #49174 backported the commit that switched the clang runtime library and moved compiles to a sysroot without GCC (the earlier sysroot carried GCC 13). That branch now has the same build setup as main, so the next v1.40.x patch release will probably carry the change; we have not checked a binary built from that branch. The 1.39 release branch does not have the switch. We do not know whether the change in code generation was intended.

The result is from one VM at low contention, between two builds that differ in more than their atomics, so it bounds the effect on that workload alone. The microbenchmark ratios below are worst cases that this run did not reach, and we never built or measured the compiler flag we name as a candidate. Any error here is ours. The work came out of our measurements of Envoy’s stats, part of our account of the whole Envoy CPU effort.

Key findings

  • End to end, no resolved difference. At 12 workers and 1,000 requests per second per worker on one Arm cloud VM, the cost of the store’s stats differed by −0.09% of worker cycles per request (95% interval −0.85 to +0.67) between the v1.40.2 release and unreleased main. At 4 workers the cell has no verdict.
  • The code generation changed. The count of exclusive-load instructions (ldaxr) in the arm64 binary went from 84 in v1.40.2 to 29,324 at main 5e1439980a (17 November) and 29,559 at main on 3 December. Main inlines LL/SC loops where the release calls out-of-line helpers. As of 3 December 2026 no Envoy release contains the change; by its build files, the release/v1.40 branch has had it since 11 November, so the next v1.40.x patch release probably will.
  • Worst case in a microbenchmark. With every thread updating one stat as fast as it can, inline LL/SC atomics cost 1.10 to 1.68 times inline LSE atomics without contention, and 4.7 times for a counter shared by 12 threads. The benchmark compares two inline forms; the release uses out-of-line helpers. The end-to-end run stayed far below this load.
  • Going back to the release’s form is untested. By our reading of the source, -moutline-atomics would bring back out-of-line helpers. We never built Envoy with it.

What this means for you: the arm64 release binaries we counted (v1.39.0, v1.40.0 and v1.40.2) use the out-of-line helpers. As of 3 December 2026, builds of main contain the inline loops, and so, by its build files, does the release/v1.40 branch since 11 November. The next v1.40.x patch release probably will too. The counting command shows which form a binary has.

The end-to-end comparison

No resolved difference at 12 workers, and no verdict at 4. Each build ran with its stats on and with every stat in the stats store rejected (reject_all: true), which prices the store’s stats for each build. The result is the difference between the two prices.

Workers Release Main Main minus release A/A Basis
12 +3.39% [+2.67, +4.11] +3.30% [+2.92, +3.67] −0.09% [−0.85, +0.67] +0.03% [−0.80, +0.85] Not resolved
4 +3.30% [+2.65, +3.95] +2.97% [+2.47, +3.47] −0.33% [−1.27, +0.61] +0.73% [+0.18, +1.29] No verdict

“Release” and “Main” are each build’s price of the store’s stats, in worker cycles per request. “A/A” is a second copy of the release against the first. 20 rounds, 200 of 200 runs valid. The 95% intervals are plain t intervals; the between-session term used on the x86 server was not estimated on this VM. Basis words are as defined in the stats post. The machine is an Arm cloud VM on Neoverse V2 cores: 16 virtual CPUs, one per core, no SMT; clock about 3.0 GHz, not fixed; a shared-tenancy spot VM with the hardware counters exposed. Load is 1,000 requests per second per worker over loopback. The prices are lower bounds on what stat updates cost, because per-host stats stay on. At 4 workers the same-build repeat differed from the first copy by more than the effect, hence no verdict. The 12-worker difference is −261 cycles per request [−2,861, +2,339], out of about 348k. The price list has the x86 server’s figure for the same rejection, at another load and worker count.

The limits of this comparison:

  • Low contention. A request made about 14 counter increments among everything else it did, far from the rate at which the microbenchmarks below stress one counter.
  • It prices only the atomics that stat updates execute. Atomics elsewhere in the proxy are in the direct comparison of the two builds: +0.37% [−0.08, +0.81] at 12 workers and +0.64% [−0.01, +1.29] at 4 (Exploratory). That comparison also contains everything else that differs between a release and main, so we do not read it as an effect of the atomics.
  • The stats work differs slightly between the builds. In the pre-run check, counter increments per request agreed between the builds to within 0.05% (14.03 to 14.04), the same spread as two copies of the release. The timed runs did not count them. Gauge updates were not counted, we did not compare the stats source of the two commits, and the instructions removed by rejecting the store’s stats differ between the builds (medians): 6.41k against 6.12k per request at 4 workers (4.6% fewer on main) and 6.43k against 6.13k at 12 (4.7%).

What changed in code generation?

One atomic update runs one instruction in the LSE form and a loop in the LL/SC form. The loop runs again when its store-exclusive fails, which happens when another core writes the same cache line between the load and the store.

An LSE atomic add is one instruction; an LL/SC atomic add is a loop that retries when its store-exclusive fails Left, LSE: one instruction, an atomic add such as ldaddal, reads, adds and writes the counter in one step; the code has no retry loop. Right, LL/SC: a loop of three steps. ldaxr loads the value and opens an exclusive reservation on its address, an add computes the new value, and stlxr stores it only if the reservation still holds; another core's write to the same cache line ends it, as can other events. If the store fails the loop starts again. Below the loop, a timeline of contention: core A loads, core B stores to the same line, which clears A's reservation, so core A's store fails and A loops again. At the bottom, how Envoy's arm64 builds get them: v1.40.2 calls an out-of-line helper from libgcc that uses LSE when the core has it and the loop otherwise; main since 26 October, and by its build files the release/v1.40 branch since 11 November, has the loop inline, even on cores with LSE. In the microbenchmark, instructions per counter increment stayed at 43.4 to 43.7 with inline LSE and rose from 50.4 at 1 thread to 84.9 at 12 with LL/SC. LSE: one instruction ldaddal x1, x0, [counter] reads, adds and writes the counter in one step under contention it is still one instruction; the code has no loop LL/SC: a loop ldaxr load, open an exclusive reservation add compute the new value stlxr store if the reservation holds store failed: back to ldaxr core A core B ldaxr stlxr fails ldaxr stlxr B’s store clears A’s reservation ENVOY ARM64 BUILDS v1.40.2 release calls an out-of-line helper (__aarch64_*, from libgcc) that uses LSE when the core has it, and the loop otherwise the core measured here has LSE main and release/v1.40 main since 26 October; release/v1.40 since 11 November (by its build files): the loop, inline, even on cores with LSE microbenchmark, one counter: instructions per increment 43.4 to 43.7 with inline LSE; 50.4 at 1 thread, 84.9 at 12 with LL/SC An LSE atomic add is one instruction; an LL/SC atomic add is a loop that retries when its store-exclusive fails Left, LSE: one instruction, an atomic add such as ldaddal, reads, adds and writes the counter in one step; the code has no retry loop. Right, LL/SC: a loop of three steps. ldaxr loads the value and opens an exclusive reservation on its address, an add computes the new value, and stlxr stores it only if the reservation still holds; another core's write to the same cache line ends it, as can other events. If the store fails the loop starts again. Below the loop, a timeline of contention: core A loads, core B stores to the same line, which clears A's reservation, so core A's store fails and A loops again. At the bottom, how Envoy's arm64 builds get them: v1.40.2 calls an out-of-line helper from libgcc that uses LSE when the core has it and the loop otherwise; main since 26 October, and by its build files the release/v1.40 branch since 11 November, has the loop inline, even on cores with LSE. In the microbenchmark, instructions per counter increment stayed at 43.4 to 43.7 with inline LSE and rose from 50.4 at 1 thread to 84.9 at 12 with LL/SC. LSE: one instruction ldaddal x1, x0, [counter] reads, adds and writes the counter in one step; under contention it is still one instruction; the code has no loop LL/SC: a loop ldaxr load, open an exclusive reservation add compute the new value stlxr store if the reservation holds store failed: back to ldaxr core A core B ldaxr stlxr fails ldaxr stlxr B’s store clears A’s reservation ENVOY ARM64 BUILDS v1.40.2 release calls an out-of-line helper (__aarch64_*, from libgcc) that uses LSE when the core has it, and the loop otherwise the core measured here has LSE main and release/v1.40 main since 26 October; release/v1.40 since 11 November (by its build files): the loop, inline, even on cores with LSE microbenchmark, one counter: instructions per increment 43.4 to 43.7 with inline LSE; 50.4 at 1 thread, 84.9 at 12 with LL/SC
The two forms of an atomic add on arm64, drawn as a sketch: the register names and the add step are illustrative. An LSE atomic is one instruction. An LL/SC atomic is a load-exclusive, the change and a store-exclusive, and the store fails if another core wrote the cache line in between, or if the reservation was cleared for another reason, so the loop runs again; the more cores write the same line, the more often it does. The instruction counts are from the microbenchmark below (one counter, inline LSE against inline LL/SC, one Arm cloud VM on Neoverse V2 cores).

The number of exclusive-access instructions in the arm64 binary rose in two steps on main, on 24 and 26 October 2026. We counted the four instructions that make up LL/SC loops in each binary’s disassembly (llvm-objdump), with the byte and halfword forms counted under their base instruction (an ldaxrb counts as an ldaxr). The release rows count the arm64 release binaries of v1.39.0 and v1.40.0. For v1.40.2 we counted both the binary we ran end to end and the binary in the official v1.40.2 image, and they give the same counts. The rows for main count the binary in the official arm64 development image of each commit.

Exclusive-load instructions (ldaxr) in Envoy's arm64 binary, from v1.40.2 to main on 3 December 2026 Horizontal bars of the ldaxr count per binary. v1.40.2 release: 84. Main at 2a39ecbfa9, 24 October: 84. Main at 7ffbe9cc49, 24 October, the toolshed 0.5.6 update: 1,122. Main at 06e236175a, 26 October, the switch to compiler-rt: 28,904. Main at 5e1439980a, 17 November: 29,324. Main at c006d6be82, 3 December: 29,559. The same counts are in the table below. 0 10,000 20,000 30,000 v1.40.2 release: 84 ldaxrv1.40.2 release84 main 2a39ecbfa9, 24 October: 84 ldaxrmain 2a39ecbfa9, 24 October84 main 7ffbe9cc49, 24 October: toolshed 0.5.6: 1,122 ldaxrmain 7ffbe9cc49, 24 October: toolshed 0.5.61,122 main 06e236175a, 26 October: compiler-rt: 28,904 ldaxrmain 06e236175a, 26 October: compiler-rt28,904 main 5e1439980a, 17 November: 29,324 ldaxrmain 5e1439980a, 17 November29,324 main c006d6be82, 3 December: 29,559 ldaxrmain c006d6be82, 3 December29,559 Exclusive-load instructions (ldaxr) in Envoy's arm64 binary, from v1.40.2 to main on 3 December 2026 Bars of the ldaxr count per binary, each label above its bar. v1.40.2 release: 84. Main at 2a39ecbfa9, 24 October: 84. Main at 7ffbe9cc49, 24 October, the toolshed 0.5.6 update: 1,122. Main at 06e236175a, 26 October, the switch to compiler-rt: 28,904. Main at 5e1439980a, 17 November: 29,324. Main at c006d6be82, 3 December: 29,559. The same counts are in the table below. 0 10,000 20,000 30,000 v1.40.2 release: 84 ldaxrv1.40.2 release84 main 2a39ecbfa9, 24 October: 84 ldaxrmain 2a39ecbfa9, 24 October84 main 7ffbe9cc49, 24 October: toolshed 0.5.6: 1,122 ldaxrmain 7ffbe9cc49, 24 October: toolshed 0.5.61,122 main 06e236175a, 26 October: compiler-rt: 28,904 ldaxrmain 06e236175a, 26 October: compiler-rt28,904 main 5e1439980a, 17 November: 29,324 ldaxrmain 5e1439980a, 17 November29,324 main c006d6be82, 3 December: 29,559 ldaxrmain c006d6be82, 3 December29,559
Count of ldaxr instructions in the arm64 envoy binary, byte and halfword forms counted under the base instruction; the release row is v1.40.2 (v1.39.0 and v1.40.0 read the same), the other rows are official development images of main. Two steps, at the envoy_toolshed update and at the switch to compiler-rt; the other three LL/SC instructions move the same way (table below).
Binary ldaxr ldxr stlxr stxr
v1.39.0, v1.40.0 and v1.40.2 releases 84 28 86 26
main at 2a39ecbfa9 (24 October) 84 28 86 26
main at 7ffbe9cc49 (24 October) 1,122 1,335 1,147 1,310
main at 28491e9130 (26 October) 1,122 1,335 1,147 1,310
main at 06e236175a (26 October) 28,904 15,507 28,773 15,638
main at 5e1439980a (17 November) 29,324 15,693 29,193 15,824
main at c006d6be82 (3 December) 29,559 15,708 29,374 15,893

We searched the 654 commits from the point where main and v1.40.0 diverge (13 October) to 5e1439980a and skipped commits without a tagged development image. The images carry no revision label, so we trust each image tag to be the build of that commit. The 3 December row is a later check of the newest development image at the time, outside that search; its binary carries the commit id as its build ID. Counted without the byte and halfword forms, the same binaries give smaller numbers, for example 45, 19, 47 and 17 for v1.40.2 and 29,309, 15,606, 29,128 and 15,787 for main on 3 December; either way the count rises by more than two orders of magnitude from the release to main.

The first step is at the commit that updates the envoy_toolshed dependency from 0.5.5 to 0.5.6, the second at the commit that switches the clang runtime library from libgcc to compiler-rt and moves compiles to a sysroot without GCC. Neither is an ancestor of v1.40.2 (checked with git merge-base --is-ancestor). The second has since been backported to release/v1.40 as 2e6a3ce4f7, in #49174, after v1.40.2 was tagged; that branch has also moved to a later envoy_toolshed.

Where the change came from: a sysroot without GCC

We established the mechanism by reading source: clang 22.1.8 (the version Envoy pins), the Bazel toolchain rules and the script that builds the sysroot. That reading agrees with the counts above; no compiler invocation log confirms it. Our first explanation was wrong.

We noticed the change through the stats microbenchmarks. Our plan had assumed that Envoy’s clang emits calls to out-of-line helpers on arm64. In our arm64 benchmark builds, which are based on main, instructions per operation on a shared counter grew with the thread count; on x86 they stayed flat.

Our first note blamed library code compiled without outline atomics. The sources disproved it. The commit adds no such build, and the runtime-library flag alone would not have changed code generation. We had also expected one step and found two.

Our current reading: clang decides the default per compile command. On AArch64 Linux, outline atomics are on by default when that command’s runtime library is compiler-rt, or when it is libgcc from a GCC installation of version 9.3.1 or later. The second commit drops the sysroot that carried GCC 13. After it, Envoy’s aarch64 compile commands use a sysroot that contains no GCC installation, and -rtlib=compiler-rt is passed on the link command only. A compile command then sees clang’s built-in default runtime library, which for this toolchain must be libgcc (inferred from the counts; we did not query the compiler), and no GCC. So the default is off and clang emits inline LL/SC loops for the ARMv8.0 baseline. Envoy’s build sets no -mno-outline-atomics, -march or -mcpu flag. The build files of main on 3 December and of the release/v1.40 branch on 2 December have the same setup.

We infer the same cause for the first step, in another place: a prebuilt V8 archive that Envoy links was rebuilt against such a sysroot, while Envoy’s own compile commands kept the earlier one. We did not disassemble that archive.

LSE against LL/SC in a microbenchmark

In a microbenchmark where every thread updates one stat as fast as it can, inline LL/SC code cost 1.10 to 1.68 times the single-instruction (LSE) code without contention, and the ratio grew with the number of threads sharing the stat. This is a worst case, and it compares two inline forms; the release uses out-of-line helpers.

Operation Not shared Shared by 4 threads Shared by 8 Shared by 12
Counter increment 1.36x [1.36, 1.37] 2.4x [2.1, 2.8] 3.2x [2.8, 3.8] 4.7x [4.1, 5.4]
Gauge::set 1.68x [1.67, 1.69] 2.5x [2.2, 2.9] 3.2x [2.8, 3.6] 3.0x [2.8, 3.3]
Primitive counter, the kind per-host stats use 1.10x to 1.13x 3.5x [3.3, 3.8] 6.2x [5.8, 6.7] 8.9x [8.3, 9.5]
Three atomic updates with no Envoy code (model) 1.39x [1.38, 1.39] 4.8x [4.1, 5.4] 8.7x [8.1, 9.3] 12.6x [11.4, 14.0]

Cycles per operation, LL/SC over LSE, on the same Arm VM (Measured). One source tree, our stats patches and benchmarks on Envoy main 5e1439980a, built twice with -c opt and clang 22.1.8: once with -march=armv8-a+lse -mno-outline-atomics, once with -march=armv8-a -mno-outline-atomics. Threads are pinned one per core. Five paired rounds, each the median of five 1-second windows; 3,200 of 3,200 windows passed the gates; 95% intervals. One gate bound (involuntary context switches) was raised after a smoke run failed it, before the measured run; under the earlier bound 468 of the 3,200 windows would have failed. The “not shared” column is one stat per thread for the first three rows and one thread for the model.

The uncontended counter increment cost 43.2 cycles with LSE and 58.9 with LL/SC; shared by 12 threads, 2,003 against 9,221. Instructions per increment stayed at 43.4 to 43.7 with LSE and rose with LL/SC (50.4, 56.6, 71.1 and 84.9 at 1, 4, 8 and 12 threads), which shows retries. How the cycle cost divides between retries and cache-line transfers was not measured.

The table does not support the second digit of the contended ratios (their half-widths are 5% to 17%), absolute contended costs to better than about 20%, any other core, VM type or thread count above 12, or any end-to-end cost. Three rounds ran the LL/SC build first and two the LSE build; an order effect is neither shown nor excluded.

Would -moutline-atomics select the earlier form?

Untested. By the same source reading, -moutline-atomics on the aarch64 compile commands would select out-of-line helpers again and keep the ARMv8.0 baseline; we never built Envoy with the flag. A second candidate follows from the same reading: passing -rtlib=compiler-rt on the compile commands as well as the link command would turn the default back on. We did not build that either, and clang may warn that the argument is unused during compilation.

The v1.40.2 release, which links libgcc statically, takes its __aarch64_* helpers from libgcc, and those are the helpers its end-to-end run used. A -moutline-atomics build with compiler-rt would take them from the compiler-rt builtins library, where the LLVM source builds them; we did not inspect the archive Envoy links. By our reading, a flag set in Envoy’s build would not reach the prebuilt V8 archive. What such a build would cost or save is open. The microbenchmark has no out-of-line arm, and the one end-to-end comparison that involves the out-of-line form resolved no difference.

-march=armv8.1-a+lse is another choice. It inlines the single-instruction form, and the binary then needs ARMv8.1 cores, which rules out ARMv8.0 cores such as the Cortex-A72. Which form Envoy’s arm64 builds use is for Envoy’s maintainers to decide.

Where are the code and the data?

  • The count table and the counting method: docs/stats-data/arm-atomics-bisect.md in the harness repository (at the tag stats-2026-11). It has no raw files; the binaries are Envoy’s own release assets and images. The v1.40.2 counts, the 3 December row, the exact-mnemonic counts and the check of the v1.40.2 image against the release binary are in its addendum of 3 December, with the SHA-256 of both binaries.
  • The end-to-end run: the asset stats-2026-11-data-arm-codegen.tar.gz (unpacked: data/stats/arm-codegen/), with its rendered table at docs/stats-tables/arm-codegen/codegen.md. The microbenchmark pair: the asset stats-2026-11-data-arm-lse-llsc.tar.gz (unpacked: data/stats/arm-lse-llsc/), with its rendered tables under docs/stats-tables/arm-lse-llsc/. Both archives are assets of the release of the tag stats-2026-11, fetched and verified with the repository’s tools/fetch-stats-data.py; the tables and checksums are in the repository at that tag.
  • The build options of the pair and the check of what the compiler emitted: examples/stats-mt/BUILDING.md (BUILDING.md).
  • The benchmark source of the pair, a tag on our Envoy fork: stats-2026-11/bench-lse-source. The published commits are cleaned copies of the commits we measured; the data keeps the measured commit ids, and two mapping files list both (docs/stats-data/envoy-commit-map.md and docs/stats-data/harness-commit-map.md). The stats post credits the work that branch builds on.

Envoy’s build and its stats code are the work of its contributors; clang and compiler-rt are LLVM’s. Corrections go to the harness’s issue tracker.

← All writing