Skip to content

Performance

This page shows how fast Dox is, and how to keep your app fast in production.

Setup

Dox is fast by default. In production, follow these rules:

  1. Build with dox build and run the AOT binary. See Deployment.
  2. Put Caddy or nginx in front, for HTTPS and gzip.
  3. Keep the default isolates, one per CPU core.
  4. Keep the body limits on.

For the code mistakes that slow an app down, see Performance mistakes.

Bodies, uploads and big responses

Dox keeps big requests and responses out of the memory by default:

  • A body over maxBodySize or maxMultipartSize gets 413 before Dart reads it. Set the same limit in the proxy. See Size limits.
  • An upload over 1 MB streams to a temp file. See Request.
  • A File or Stream response streams. See Files and big responses.

gzip

A proxy does gzip better than Dart, so gzip in Dart is off by default. With no proxy, turn it on:

AppConfig(compress: true);

Dox gzips only a body over 256 bytes, for a client that accepts gzip. A streamed response is not compressed.

compressLevel sets how hard gzip works, from 1 to 12. The default is 1: it is fast, and the body is a little bigger. A higher level takes more CPU for a smaller body:

AppConfig(compress: true, compressLevel: 6);

For a 6.7 kB JSON body:

Level Time Size
1 (default) 13.5 µs 1,421 bytes
6 32.6 µs 1,270 bytes

Use a low level when the server CPU is the limit, as for most APIs. Use a higher level when the network is slow and the bodies are big. The client reads every level the same way. Levels 10 to 12 are slow and use 9 MB of memory each. One thread gzips all answers of a server, so a slow level makes the other gzipped answers wait.

Logging

LogMiddleware logs one line per request. A new project turns it off when APP_ENV is production or not set, because the proxy writes access logs.

Logger writes its lines every 20 ms in one write. If the process is killed hard, the last 20 ms of logs can be lost.

Response handler

Leave responseHandler unset if you do not need it. With no handler, Dox sends a plain value (text, map, list) with no DoxResponse.

JSON

The type that a controller returns sets how fast Dox writes the JSON. From the fastest to the slowest:

  1. A @Dto or a @Serialize() class. The generated code writes the fields directly into the bytes of the response.
  2. A model. Its generated writeJson() also makes no Map.
  3. A plain Map, or a class with only toJson(). Dox makes or reads a map for each response.

Run dart run build_runner build to get the generated code. The encode time:

Response Before Now
A list of 40 rows (6.7 kB), with the Dox encoder only 41 µs 16.5 µs
A list of 40 models with two dates each (6.3 kB) 44 µs 8 µs
A list of @Dto objects, 1 to 50 items 7.5 µs 2.8 µs

On the data of the last row and on the same machine, JSON.stringify of Bun takes 3.3 µs.

CoreFlags.sdkJsonEncoder makes Dox use the slower encoder of the Dart SDK. It is off by default: turn it on only to find out if the Dox encoder causes a wrong response. See Core flags.

To write the JSON of a class by hand, see Write the JSON yourself.

Benchmark

This benchmark uses the rules of the-benchmarker/web-frameworks. Each server answers GET / (empty body), GET /user/:id (the id) and POST /user (empty body). "Dox server only" is dox_http_native with no framework.

It measures only the HTTP stack. A real app spends most of its time on the database and your own code. See App benchmark.

2 cores

2 cores: ahead of Rust hyper and Bun

GET /, 256 connections. Every server has one worker per core: Dox and Relic one isolate, Bun and Node one process, Go and Rust one thread.

req/s p99 RAM
Doxfull app 652,400fastest 0.7 ms 21 MB
Rusthyper 572,1321.14× slower 0.8 ms 14 MB
BunBun.serve 504,6721.29× slower 1.0 ms 40 MB
Relic 2relic_native 471,0051.39× slower 0.7 ms 40 MB
Nodenode:http 282,1302.3× slower 1.7 ms 199 MB
Gonet/http 237,1462.8× slower 3.3 ms 36 MB
dart:ioHttpServer 124,9965.2× slower 4.8 ms 56 MB

Dox · Rust 1.99 · Bun 1.4 · Relic 2.0 · Node 26 · Go 1.26 · Dart 3.13 · 2 cores · 256 connections · wrk

All the servers are from the same run on 2026-11-22. Each number is the median of 3 rounds. See How it was run.

Requests per second on GET / at 64, 256 and 512 connections:

Server 64 256 512 p99 at 256 peak MB
Dox 541,489 652,400 669,691 0.74 ms 21
Dox server only 576,078 685,300 701,441 0.70 ms 20
Rust
hyper
499,992 572,132 559,617 0.77 ms 14
Bun
Bun.serve
496,865 504,672 521,648 1.02 ms 40
Relic 2
relic_native
461,710 471,005 494,225 0.71 ms 40
Node
node:http
263,438 282,130 278,923 1.73 ms 199
Go
net/http
245,400 237,146 230,919 3.32 ms 36
dart:io 115,790 124,996 132,746 4.82 ms 56

The other two routes at 256 connections:

Server GET /user/:id POST /user
Dox 582,861 576,435
Dox server only 666,149 676,363
Rust
hyper
553,689 563,347
Bun 488,315 496,905
Relic 2 432,465 376,030
Node 268,959 291,521
Go 229,640 232,201
dart:io 94,084 124,623

Why it is fast

The server runs on the thread of the isolate, so a request never waits for another thread to wake up. See Native server. A profile with perf (4 server cores, 64 connections):

Dox Bun
CPU time per request 4.85 µs 5.5 µs
Context switches per request 0.08 0.035

How it was run

  • Docker on an Apple M2 (8 CPUs in the Docker VM), linux/arm64.
  • One server at a time. The server and wrk run in two containers on different CPUs: the server on 2 CPUs, wrk on the other 6. Host network, keep-alive.
  • wrk 4.1, 64, 256 and 512 connections, 5 seconds warm-up, then 15 seconds per route.
  • 3 rounds on 2026-11-22. In each round, every server runs one time. The tables show the median of the 3 rounds.
  • Every server has as many workers as server CPUs.
  • Peak memory is the peak of the container (all workers).
  • Dart 3.13.7, AOT build with dart build cli (this is what dox build does). dox_core and dox_http_native are the releases of 2026-11-22. Node 26.13, Bun 1.4.5, Go 1.26, Rust 1.99 with hyper 1.
  • Relic is relic 2.0.0 with relic_native 2.0.0, started with serveNative().

App benchmark

A small real app, the same in each language: GET /json returns a map, GET /db reads one row by id from Postgres, and GET /queries?n=20 reads 20 rows one after another. The table has 10,000 rows, and each app uses its database driver with no ORM.

2 cores: one row from Postgres

GET /db, 256 connections. Requests per second, higher is better.

req/s p99 RAM
Doxdox_postgres_native 297,000fastest 2.6 ms 93 MB
BunBun.sql 198,2961.5× slower 2.1 ms 64 MB
Rusttokio-postgres 128,0652.3× slower 2.6 ms 11 MB
Nodepg 75,4473.9× slower 4.1 ms 232 MB
Gopgx 55,9035.3× slower 6.3 ms 31 MB
dart:iopackage:postgres 28,59810.4× slower 14.2 ms 47 MB

Dox · Bun 1.4 · Rust 1.99 · Node 26 · Go 1.26 · Dart 3.13 · Postgres 18 · 2 cores · 256 connections · wrk

The Dox numbers are from 2026-11-16. The other servers are from the run before, on the same Mac.

All three routes at 256 connections, requests per second:

Server /json /db /queries?n=20 peak MB
Dox
dox_postgres_native
592,900 297,000 18,015 93
Bun
Bun.sql
564,362 198,296 18,994 64
Rust
hyper + tokio-postgres
667,718 128,065 9,312 11
Node
node:http + pg
205,774 75,447 7,458 232
Go
net/http + pgx
206,398 55,903 6,635 31
dart:io
package:postgres
89,480 28,598 2,269 47
  • On one query per request, Dox is the fastest: 1.5 times Bun.
  • On 20 queries per request, Dox and Bun are about the same. Postgres is the limit here. Both are about twice as fast as Rust.

The same app on MySQL 8.4 (dox_mysql_native). The dart:io app has no MySQL version.

Server /json /db /queries?n=20 peak MB
Dox
dox_mysql_native
558,886 247,242 12,347 70
Bun
Bun.sql
561,340 201,923 12,676 65
Rust
hyper + mysql_async
653,244 46,795 3,158 10
Node
node:http + mysql2
205,630 74,809 6,001 239
Go
net/http + go-sql-driver
211,713 55,322 5,520 27

How it was run: the same rig as the benchmark above. The server gets 2 CPUs, the database gets 2 CPUs and wrk gets the other 4. Each server has 4 database connections per core, 8 in total. One run of 15 seconds per route. The Postgres Dox row was measured again on 2026-11-16 (same Mac, a new Docker VM). The other servers and the MySQL table are from the run before.

Database drivers

One find-by-id query, AOT build (dart build cli), database on the same machine (Apple M-series), one isolate:

Database One query at a time Many queries in flight App CPU time per query
Postgres 14
4 connections
60 µs 12.5 µs each
64 in flight
MySQL 8.4
10 connections
67 µs 11 µs each
32 in flight
13.5 µs
MariaDB 11
10 connections
63 µs 9.7 µs each
32 in flight
12.4 µs

The CPU time counts the Dart thread and the Rust thread. For MySQL, it is about 75,000 queries per second on one core. Many requests at the same time, like in a web server, get the most out of the driver.

Dart VM flags

A bigger young generation (DART_VM_OPTIONS=--new_gen_semi_max_size=64 or 128) did not give a better p99 in 5 runs, so Dox sets no VM flags. The AOT binary of dox build reads DART_VM_OPTIONS, so you can try your own.

Next steps