Dox patch release: 29 November 2026
This release is patch versions only. Dox now writes JSON directly into the bytes of the response, and each request makes fewer objects. Thus the server does more requests a second and uses less memory.
Key takeaways
- Faster JSON. A JSON route does 30% more requests a second on HTTP/1.1 and 37% more on HTTP/2. See Benchmark.
- Less memory. The peak memory of a small app goes from 18 MB to 12 MB. On the pipelined test it goes from 53 MB to 22 MB.
- Faster model responses. A route that returns 100 model rows does 44% more requests a second.
- New: return a
@Dtofrom a controller.@Serialize()makes a serializer fast too.- New: more ports in one process. Set
additionalPortsin the app config.- Easy to update. Run
dart pub upgrade, thendart run build_runner build. Then check Read before you update.
Versions
| Package | New version |
|---|---|
dox_http_native |
3.2.7 |
dox_core |
3.2.7 |
dox_builder |
3.2.3 |
dox_annotation |
3.2.1 |
dox_orm |
3.2.5 |
dox_migration |
3.2.5 |
dox_cache_database |
3.2.5 |
dox_view |
3.2.1 |
dox CLI |
3.2.4 |
| App template | v3.2.7 |
dox_migration and dox_cache_database have no changes. Their version goes up with dox_orm. The app template only gets the new minimum versions.
No change: all the other packages.
How to update
-
Get the new versions:
-
Make the generated code again. The new
dox_builderwrites the fast JSON code: -
Update the CLI:
-
Build or start the app again. The new native library downloads automatically.
-
Read Read before you update.
There is no API change. The JSON of each response is the same as before.
Benchmark
We ran the same apps on the 3.2.6 packages from pub.dev and on this release. The rig is Docker on an Apple M2, with 2 server cores. Each number is the median of 3 rounds.
Pipelined requests: 54% more, less than half the memory
GET / with pipelined HTTP/1.1 requests.
2 server cores · Docker on an Apple M2 · median of 3 rounds
JSON on HTTP/1.1: 30% more requests
GET /json: a JSON response on HTTP/1.1.
2 server cores · Docker on an Apple M2 · median of 3 rounds
JSON on HTTP/2: 37% more requests
GET /json on HTTP/2 with no TLS (h2c).
2 server cores · Docker on an Apple M2 · median of 3 rounds
RAM is the peak memory of the whole server.
HTTP
| Test | 3.2.6 | This release | Change | p99 | Peak memory |
|---|---|---|---|---|---|
Pipelined GET / |
2.02M | 3.12M | +54% | 8.0 → 3.9 ms | 53 → 22 MB |
/json, HTTP/1.1 |
194K | 253K | +30% | 3.9 → 1.9 ms | 17 → 11 MB |
/json, HTTP/2 (h2c) |
238K | 325K | +37% | 7.5 → 4.7 ms | 46 → 43 MB |
| hello app, 3 routes, 64, 256 and 512 connections | +4% to +7% | same | 18 → 12 MB |
The first three rows are requests a second. The hello app is a full Dox app with three small routes.
Database
These routes use Postgres. The numbers are requests a second.
| Route | 3.2.6 | This release | Change | p99 |
|---|---|---|---|---|
/orm-list, a list of model rows |
34K | 49K | +44% | 10.8 → 7.6 ms |
/orm-preload, models with a relation |
29K | 37K | +28% | 13.5 → 10.4 ms |
/orm-tx, a transaction |
11.3K | 13.4K | +19% | same |
/json of the database app |
597K | 667K | +12% | 0.84 → 0.72 ms |
/db, /qb, /orm-first, one row |
+6% to +7% | same | ||
/queries?n=20, 20 queries |
+4% | same | ||
/orm-update |
no change | same |
JSON encode time
These numbers are the time to encode one response, not requests a second.
| Data | Before | This release |
|---|---|---|
| A list of 40 rows (6.7 kB) | 41 µs | 16.5 µs |
| A list of 40 model rows with two dates each (6.3 kB) | 44 µs | 8 µs |
A page of dox_view with 201 rows (25 kB), render and encode |
199 µs | 67 µs |
A list of @Dto objects encodes in 2.8 µs. On the same data and the same machine, JSON.stringify of Bun takes 3.3 µs.
The page test of dox_view does 35% more requests a second on 4 server cores.
What the numbers do not show
- Some routes do not get faster.
/queries?n=20gets only 4%, because Postgres is the limit./orm-updatedoes not change. - The first minute has a small p99 increase. In the first minute after the start, the p99 of this release is approximately 1 ms higher one time. After that, the p99 is equal or better.
- gzip was not in this comparison. We did not run the test with gzip responses on the two versions.
- This is one machine. The results of the public HttpArena run are still to come.
Why it is faster
JSON goes directly into the bytes
Before, a JSON response had three steps:
toJson()made aMapfor each object.- The JSON encoder went through the map. The map has no types, so the encoder did a type check on each value.
- The encoder made a copy of each value into the response.
Each step makes objects that the garbage collector must remove later.
Now dox_builder writes code for each class. This code knows the type of each field. It writes the fields into the bytes of the response in one pass, with no map. The keys, the commas and the brackets are fixed bytes from build time.
Three types of class get this code:
- A
@Dtoclass. - A model, which gets a
writeJson()method. - A serializer or a plain class with
@Serialize().
All other values use the new JSON encoder of Dox. It replaces JsonUtf8Encoder of the Dart SDK. For a small body, it is 2.5 to 3 times faster.
Fewer objects for each request
- The router reads the path with no
Uri. Before, each request made aUrifor its path. - A request makes fewer objects. The headers and the client address stay as offsets until a handler reads them. On the pipelined test, Dart allocates 1,024 bytes for each request, not 1,297 bytes.
- Pipelined answers go directly into the write buffer. Before, each answer after the first one used a new buffer and a copy.
- A batch of requests is 128 kB, not 256 kB. The smaller batch stays in the young space of the Dart heap, so the garbage collector removes it quickly.
- HTTP/2 uses the HPACK dynamic table. The header block of an answer goes from approximately 169 bytes to approximately 44 bytes.
- gzip uses libdeflate. For a 6.7 kB JSON body, the gzip time goes from 35.7 µs to 13.5 µs.
See Performance.
New
Return a DTO from a controller
A controller can return a @Dto object or a list of them:
@Dto()
class ProductView {
final int id;
final String productName;
final DateTime? soldAt;
const ProductView({required this.id, required this.productName, this.soldAt});
}
- The JSON has the keys that the DTO reads:
product_nameforproductName. - A
DateTimebecomes ISO 8601 text. An enum becomes its name. - The DTO must be in
AppConfig(dtos: dtos).
See Returning a DTO.
Fast serializers with @Serialize()
Add @Serialize() and the part line to a serializer. Then run dart run build_runner build:
import 'package:dox_core/dox_core.dart';
part 'post.serializer.g.dart';
@Serialize()
class PostSerializer extends Serializer<Post> {
PostSerializer(super.data);
@override
Map<String, dynamic> convert(Post m) {
return <String, dynamic>{
'id': m.id,
'title': m.title,
};
}
}
- The serializer writes the same JSON, with no map.
- Set
AppConfig(container: registerContainer), so that Dox finds the generated code. @Serialize()also works on a plain class. Dox then writes its public final fields as JSON.- If
convert()has a shape that the generator can not read, the serializer keeps its map. The build log shows a warning.
The CLI helps here. dox make:serializer Post now adds @Serialize() and the part line. With --folder, the file goes in lib/app/serializers/post/.
See Serializer.
Faster model responses
A model in a JSON response gets a writeJson() method from the generator. You do not change your code. Run dart run build_runner build to get the method. toJson() and toMap() do not change.
More ports in one process
Set additionalPorts to make each isolate listen on more ports:
AppConfig appConfig = AppConfig(
serverPort: 8080,
additionalPorts: <int>[8082],
// ...
);
- All the ports have the same routes and the same settings.
- An app that needs two ports does not need a second process.
PORTin the env changes onlyserverPort.maxConnectionsis a limit for each port.
See App config.
A gzip level
AppConfig(compressLevel:) sets the gzip level of compress, from 1 (fast) to 12 (small). The default is 1. See Read before you update.
Send bytes that are already encoded
DoxResponse.contentBytes(bytes) sets a body of UTF-8 text as bytes. Dox sends the bytes as they are, with no second encode. dox_view uses this for view().
See Response.
Security: secret headers in HTTP/2
HTTP/2 answers now send set-cookie, cookie, authorization and proxy-authorization as never indexed (RFC 7541, section 7.1.3). These lines do not go in the HPACK dynamic table. Thus an attacker on the same connection can not find a secret from the sizes of the answers.
Fixes
- A cookie that is not valid. A cookie that the native server refuses, for example with a line break in its domain, made the request get no answer. Now the client gets a
500. - A query escape that is not UTF-8. A query such as
?a=%ffgave a500. Nowreq.queryand a@Dtothat reads the query give a400. - A server leak after an isolate stops. When an isolate stopped after an error that was not caught, its server kept 2 open files and its buffers. Now the server frees all of them.
Read before you update
dox_core3.2.7 needsdox_http_native3.2.7.dox_view3.2.1 needsdox_core3.2.7.dart pub upgradegets them together.- Run
dart run build_runner build. Without the new generated code, the app works, but DTOs and models do not get the fast JSON code. - gzip responses are a small quantity bigger. The default gzip level is now 1. A 6.7 kB JSON body becomes 1,421 bytes, not 1,271 bytes. Set
compressLevel: 6to get approximately the same size as before. maxConnectionsis a limit for each port. This has an effect only if you setadditionalPorts.- One error detail changes. If a map has a key that is not a
Stringand also a value that is not JSON, the error can name the value and not the map. - You can go back to the old JSON encoder. If you think that a response is wrong, set
CoreFlags(sdkJsonEncoder: true). The JSON is the same, but it is slower. Tell us about the response in a GitHub issue.
Full list: the CHANGELOG of each package.