diff --git a/README.md b/README.md index 5d3f6ad..63e1e7b 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,10 @@ In one benchmark service, moving from Pydantic models to msgspec Structs with th increased throughput by 68% on a route with a large JSON body and by 11% to 13% on database-backed routes; see the Benchmarks section below. -This is a prototype. Its API may change, and it relies on private FastAPI internals, so -it is pinned to FastAPI 0.142.2 to 0.147.x. It is a personal project, not part of -msgspec; feedback is welcome in the issues. +This project uses ZeroVer: the major version will always stay at 0. There will be no +1.0 release. The API may change in 0.x releases. The router relies on private FastAPI +internals, so it is pinned to FastAPI 0.142.2 to 0.147.x. It is a personal project, +not part of msgspec; feedback is welcome in the issues. ## Installation @@ -55,6 +56,10 @@ is no cache. | `GET /cities?limit=100`, a page of 100 cities read from PostgreSQL | 514 → 569 | **+10.7%** [+9.9%, +11.5%] | 1,944 → 1,757 µs | **-9.7%** [-10.3%, -9.0%] | | `POST /cities/search`, small JSON filter bodies, a page of 100 cities | 447 → 505 | **+12.9%** [+12.1%, +13.7%] | 2,237 → 1,981 µs | **-11.4%** [-12.1%, -10.8%] | +![Throughput: FastAPI with Pydantic versus MsgspecRouter with Structs, with paired relative changes and nominal 95% intervals](docs/images/benchmark-throughput.svg) + +![API CPU time per response: FastAPI with Pydantic versus MsgspecRouter with Structs, with paired relative changes and nominal 95% intervals](docs/images/benchmark-cpu.svg) + The first route returns a constant 16-byte response (`{"accepted":100}`), so the difference on this route comes mostly from request decoding and validation, and the gain is largest there. On routes that read from a database, API CPU time per response falls by diff --git a/docs/images/benchmark-cpu.svg b/docs/images/benchmark-cpu.svg new file mode 100644 index 0000000..e06618d --- /dev/null +++ b/docs/images/benchmark-cpu.svg @@ -0,0 +1,401 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + 500 + + + + + + + + + + + + + 1,000 + + + + + + + + + + + + + 1,500 + + + + + + + + + + + + + 2,000 + + + + + + + + + + + + + 2,500 + + + + Microseconds per response (lower is better) + + + + + + + POST /cities/validate + + + + + + GET /cities?limit=100 + + + + + + POST /cities/search + + + + + + + + + + + + + + + + + + + + + + + + + + 621 + + + 1,944 + + + 2,237 + + + 370 + + + 1,757 + + + 1,981 + + + + + + + FastAPI + Pydantic + + + + + + MsgspecRouter + Structs + + + + + + + + + + + + + + + + + + + -40% + + + + + + + + + + + + + -20% + + + + + + + + + + + + + 0% + + + + Paired estimate, nominal 95% interval + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -40.4% [-40.7%, -40.1%] + + + -9.7% [-10.3%, -9.0%] + + + -11.4% [-12.1%, -10.8%] + + + Relative change vs Pydantic + + + + API CPU time per response + + + One service · dedicated-vCPU cloud VM · October 2026 + + + 8 paired ABBA/BAAB blocks. Absolute values and relative estimates use different summaries; see README methodology. + + + + + + + + + + + diff --git a/docs/images/benchmark-throughput.svg b/docs/images/benchmark-throughput.svg new file mode 100644 index 0000000..53a030c --- /dev/null +++ b/docs/images/benchmark-throughput.svg @@ -0,0 +1,446 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + 500 + + + + + + + + + + + + + 1,000 + + + + + + + + + + + + + 1,500 + + + + + + + + + + + + + 2,000 + + + + + + + + + + + + + 2,500 + + + + + + + + + + + + + 3,000 + + + + Requests per second (higher is better) + + + + + + + POST /cities/validate + + + + + + GET /cities?limit=100 + + + + + + POST /cities/search + + + + + + + + + + + + + + + + + + + + + + + + + + 1,610 + + + 514 + + + 447 + + + 2,703 + + + 569 + + + 505 + + + + + + + FastAPI + Pydantic + + + + + + MsgspecRouter + Structs + + + + + + + + + + + + + + + + + + + 0% + + + + + + + + + + + + + 20% + + + + + + + + + + + + + 40% + + + + + + + + + + + + + 60% + + + + + + + + + + + + + 80% + + + + Paired estimate, nominal 95% interval + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +67.9% [+67.0%, +68.7%] + + + +10.7% [+9.9%, +11.5%] + + + +12.9% [+12.1%, +13.7%] + + + Relative change vs Pydantic + + + + Throughput in the benchmark service + + + One service · dedicated-vCPU cloud VM · October 2026 + + + 8 paired ABBA/BAAB blocks. Absolute values and relative estimates use different summaries; see README methodology. + + + + + + + + + + +