Envoy performance · part 4 of 6
What a 1,000-route table costs Envoy per request
By Otto van der Schaaf, We-Amp · · updated
With a routes list, Envoy picks a route by checking a virtual host’s routes in order until one matches. With 1,000 routes and the match in last place, that scan cost about 335 user-space instructions for every route it passed over. Checking each route’s path before its other criteria removed 29% of the user-space instructions per request and cut Envoy’s cycles per request by 11% (95% interval: 10% to 12%) for a direct response, at both load levels we tested.
This is this table’s worst case. An earlier match saves less, and the saving per route depends on what its other criteria cost to check; we measured only this table. The changes here are patches on our Envoy fork: none has been proposed to the Envoy project or reviewed by Envoy maintainers. Envoy performance, measured has the method and what did not hold up.
Contents
- What does a 1,000-route table cost per request?
- How does checking the path first work?
- What does checking the path first save?
- Does it change latency?
- What about an index of the routes?
- What about constant headers on a route?
- How we measured
- Where are the code and the data?
What does a 1,000-route table cost per request?
About 335 user-space instructions per route passed over: 410.9k per request with 1,000 routes and the match last, 76.3k with one route. Path first brought the 1,000-route request to 290.3k without changing which route is selected.
A routes list promises the first match in configured order, and a linear scan is the direct way to keep that promise. For large tables Envoy offers the matcher tree (VirtualHost.matcher). Envoy’s own benchmark of an exact-path map stays flat on our test machine at about 1.2 µs per iteration, building the request included, from 1 to 16,384 routes. A matcher tree has its own semantics (exact maps, longest-prefix maps, nested matchers), so moving a mixed first-match table onto one is a configuration change, not a drop-in. The question here is what a routes list costs at this size, and how much can be recovered without changing its promise.
The test table is one virtual host of direct responses. The first N−1 routes are drawn at random, each with these odds: 60% a distinct prefix, 20% an exact path and 20% a regex, and 30% a header matcher for a header the client never sends. The last route is prefix: /target/, and every request is GET /target/x, so the scan visits the whole table.
| Routes | Unmodified | Path first | Change |
|---|---|---|---|
| 1 | 76.3k | n/a | |
| 200 | 143.0k | 118.7k | 17.0% fewer |
| 1,000 | 410.9k | 290.3k | 29.3% fewer |
User-space instructions per request at 2,000 requests per second, medians over 16 rounds (12 for one route); path first was lower in 16 of 16 rounds. At the higher load the counts were within 0.6k of these. We give the scan’s cost in instructions only, because the one-route runs were not in the same rounds as the others.
How does checking the path first work?
At Envoy main 8ce942ce5, for prefix, exact-path and path-separated-prefix routes, matches() first calls matchRoute(), which checks the runtime fraction, gRPC, header, query parameter, cookie, TLS, metadata and filter-state criteria and stops at the first that fails. Only then is the path compared. In a long table almost every route fails on the path, so the scan pays for checks on routes the path would have rejected. The change swaps the two conditions (for path-separated prefixes, the same reorder as an early return):
// before
if (RouteEntryImplBase::matchRoute(route_match_context, stream_info, random_value) &&
path_matcher_->matchPathWithoutQuery(route_match_context.sanitizedPathWithoutQuery())) {
// after
if (path_matcher_->matchPathWithoutQuery(route_match_context.sanitizedPathWithoutQuery()) &&
RouteEntryImplBase::matchRoute(route_match_context, stream_info, random_value)) {
Neither side changes state the other reads: Envoy’s RouteMatchContext, added upstream in #44663, computes the sanitized path once per request and caches it. The selected route and the first-match order stay the same. The case that costs more is a route whose path matches but whose other criteria reject the request: it now evaluates both conditions. So the change does not help where routes share a path and differ by headers, runtime fraction or gRPC (header-based versions, canary splits), and it saves little where routes have no other criteria.
Regex and URI-template routes keep the original order. An earlier revision reordered them too. On our benchmark of regex routes that each require a header the request does not send, that revision ran 2.1 to 4.1 times slower than main in every round: with the pattern first, every route runs its regex even when a header check would have rejected it for less. In earlier instruction-count runs, keeping the original order for regex routes cost 7.6% more instructions on our table than that revision. We accepted that: the loss when the order is wrong is much larger than the gain when it is right.
What does checking the path first save?
About 11% of cycles per request with 1,000 routes and about 4% with 200, at both load levels, from 29% and 17% fewer user-space instructions. User-space cycles fell about 14% at 1,000 routes, total cycles less, since the change removes no kernel work. The higher rates, kept from our earlier runs after a gate check, run the unmodified build’s workers 67% busy (16,000 requests per second, 1,000 routes) and 58% (22,000, 200 routes).
| Routes | Requests/s | Unmodified | Path first | Change (95% interval) |
|---|---|---|---|---|
| 200 | 2,000 | 370.5k | 357.1k | 3.7% fewer (2.8% to 4.5%) |
| 200 | 22,000 | 238.6k | 228.7k | 4.4% fewer (3.7% to 5.0%) |
| 1,000 | 2,000 | 526.4k | 462.8k | 11.4% fewer (10.3% to 12.4%) |
| 1,000 | 16,000 | 378.3k | 338.2k | 11.0% fewer (10.3% to 11.7%) |
Cycles per request, medians over 16 rounds; path first was lower in 16 of 16 rounds on every row. The change column is the geometric mean of the per-round ratios.
Read the absolute cycles as this machine’s. At 2,000 requests per second the proxy is 9% to 13% busy and each request wakes a sleeping worker, so a request costs more there, and the kernel part is mostly loopback networking. The cycle saving also depends on load: with 1,000 routes, 59.5k per request at 2,000 requests per second (95% interval: 53.8k to 65.3k) and 41.5k at 16,000 (38.7k to 44.3k), paired means, from about 120k fewer instructions at both.
At 16,000 requests per second the cheaper build’s workers are less busy (60% against 67%) and wake more often per request, so its kernel cycles per request were about 5% higher (95% interval: 3% to 6%). The 11% is net of that.
An earlier run under the load generator’s default connection reuse put the 200-route saving inside the noise; with the load spread evenly it is 4%, outside it. That run’s 1,000-route path-first cycle, p99 and instruction results held.
Does it change latency?
Yes, by an amount that depends on load. At 16,000 requests per second, with the unmodified build’s workers 67% busy, near the point where queueing sets in, p99 latency fell by about 23% (95% interval: 16% to 30%), lower in 15 of 16 rounds. That figure belongs to that load: at 2,000 requests per second, 13% busy, p99 fell by 9% (7% to 11%), where the second copy of the unmodified build came within 2% of the first.
Latency is noisy at the higher rates. At 16,000 requests per second the second copy of the unmodified build came out 0.9% higher than the first (95% interval: 6.3% lower to 8.6% higher), so this setup does not resolve a p99 difference under about 6% to 8% there. With 200 routes at 22,000 requests per second, p99 fell by 11% (95% interval: 4% to 17%), lower in 12 of 16 rounds; the second copy’s interval there ran from 5.6% lower to 8.2% higher, so that result is only just resolved. Latency is as the load generator sees it over loopback, its own time included.
What about an index of the routes?
In the scan’s worst case, which is the index’s best (1,000 routes, match last), a prototype index of the routes by path removes, against the unmodified build, 81% of the user-space instructions and 38% of cycles per request at 2,000 requests per second, 42% at 16,000 (95% intervals: 37% to 38% and 41% to 42%). It is not proposed upstream, not linked from this post and not reviewed by Envoy maintainers. Its tests compare its route choice with the linear scan’s on fixed cases and seeded random tables, not on production tables. In microbenchmarks it is slower than path first with 2 to 4 routes (8% to 32%) and for regex routes at every size (3.6% to 38.8%), and we have not measured its memory or configuration-load cost.
We give no latency figures for it: at 16,000 requests per second its workers were 40% busy against 67%, a lightly loaded proxy against one close to queueing. An early revision misrouted some regex routes, as the price list’s list of withdrawn results describes. Whether Envoy wants a second mechanism beside the matcher tree is not our call.
What about constant headers on a route?
Holding config-constant header values by reference instead of copying them removes 20% of the user-space instructions on a direct-response route that adds 52 constant response headers, plus 8 on the virtual host: 32.9k fewer per request (166.3k to 133.4k), about 550 for each of the 60 applied, lower in 24 of 24 rounds. The route’s 57 request headers are not in these figures: Envoy’s router adds request headers only on the way to an upstream, so a direct response never applies them. Cycles per request fell 3.4% (95% interval: 2.5% to 4.4%) at 2,000 requests per second and 4.0% (3.4% to 4.7%) at 20,000. A route with fewer constant headers saves less. The runs carry a second copy of the unmodified build for noise, but no equal-work run of the changed build, so the cycle figures may carry a code-layout effect of up to about 1.5%; the instruction count is the firmer result. In microbenchmarks, from earlier runs and not this session, the constant path is 24% to 32% faster.
At Envoy main 8ce942ce5, Envoy’s header parser, which the router and several other components use to apply configured headers, stages each configured value as an owned string and copies it into the header map. Copying was the safe default under the header map’s lifetime rules. A constant value, though, sits in the same configuration entry as its key, and the key was already passed by reference, so referencing the value adds no new lifetime requirement. Values produced by a formatter keep the copy. The router tests pass under AddressSanitizer; we have not run the other users’ tests under it.
How we measured
One bare-metal test machine: two Intel Xeon E5-2673 v4 sockets, fixed at 2.3 GHz, turbo off. Envoy ran 4 workers on 4 cores of one socket, SMT siblings idle, exact_balance on the listener. Nighthawk ran on the other socket and sent a fixed, open-loop request rate over HTTP/1.1 and 512 loopback connections, spreading requests over every connection. (The author of this post is an emeritus maintainer of Nighthawk.) perf stat counted the Envoy process alone over a 20-second window per run, and every per-request figure divides a counter by Envoy’s downstream_rq_2xx count, scaled to that window. The builds are -c opt Envoy main at 8ce942ce5, with and without each change, measured in one session on 16 November 2026.
Every comparison interleaves the builds over 12 to 24 rounds. The route-table and header comparisons (16 and 24 rounds) also carry a second copy of the unchanged build; it came within about 0.5% of the first on cycles in all six workloads, with 95% intervals reaching 1.5%. The builds ran at the same request rate, not at the same busy level.
With a single route the unmodified, path-first and index builds run the same number of instructions per request to within 0.1%, and their cycles differ by up to about 1.5%. With the work held equal, that is what a different binary layout alone can produce, so we attribute nothing that small to a change. The smallest route result above, 3.7%, is more than twice that, and its interval stays above it.
This does not cover a match in other positions, tables where many routes share a prefix, many virtual hosts, proxied responses, filter chains that select the route again, TLS, HTTP/2 or HTTP/3, route updates over RDS, other CPUs, builds with PGO, or route tables taken from production.
Where are the code and the data?
patches/route-match-path-first-v4: path first, one commit against8ce942ce5, with a semantic test and three benchmarks. The measured build is this commit.patches/router-header-reference-v3: constant headers by reference, one commit against8ce942ce5, with a unit test of value lifetime that also passes without the change. The measured build has the same source tree as this branch.
Any error in them is ours.
The harness, the same one behind our price list of Envoy settings, is public at github.com/We-Amp/envoy-price-list (code under Apache 2.0, data under CC BY 4.0). The route tables, the header route and the configs of this session are in examples/route-table/, and the raw data and tables of all four runs in data/route-table/. Corrections and your own results, worse ones included, go to the harness’s issue tracker.
Envoy’s route matching, header code, matcher tree and benchmarks are the work of its contributors.