3 · Bulk OLTP Read & Slotted Memory (bulk_read_oltp)#
← All benchmarks · Related chapter: Chapter 1 · First Check-In
Hydrate 5,000 typed ORM model instances in deterministic order. No pipelining, no Arrow, no wire JSON shortcuts — pure PostgreSQL binary wire decoding straight into Python __slots__ models (pgdorm) versus peer ORM hydration and identity-map/session machinery.
Chart & metrics#
| ORM | Instr (Client + PG) | Heap/row | Peak Py | RTTs | Server ms | ms (med) |
|---|---|---|---|---|---|---|
| pgdorm | 73.0M (43.5M + 29.5M) | 380 B | 1.82 MiB | 1 | 3.45 ms | 6.76 ms |
| SQLDataclass | 165.7M (129.8M + 35.9M) | 361 B | 1.73 MiB | 3 | 3.47 ms | 13.91 ms |
| Django ORM | 249.5M (214.7M + 34.8M) | 549 B | 2.94 MiB | 1 | 2.47 ms | 16.20 ms |
| SQLAlchemy 2 | 289.7M (259.9M + 29.8M) | 1914 B | 9.84 MiB | 3 | 3.13 ms | 24.06 ms |
| Peewee | 301.8M (268.4M + 33.4M) | 921 B | 4.43 MiB | 1 | 2.54 ms | 20.75 ms |
| SQLModel | 355.1M (307.0M + 48.1M) | 2116 B | 10.96 MiB | 3 | 1.96 ms | 25.02 ms |
| Tortoise ORM | 396.5M (365.0M + 31.4M) | 570 B | 3.09 MiB | 2 | 2.13 ms | 25.60 ms |
| Piccolo ORM | 420.5M (390.0M + 30.5M) | 548 B | 4.09 MiB | 2 | 2.03 ms | 24.57 ms |
Ferris' basement: Why some peers need 2–3 RTTs for one SELECT
Watching the raw PostgreSQL v3 wire caught two real-world protocol costs you never see in SQL logs:
- SQLAlchemy 2 & SQLModel (
3 RTTs):AsyncSessionimplicitly issuesBEGINbefore the firstSELECTandROLLBACKon session close unless explicitly placed inAUTOCOMMITmode. - Tortoise & Piccolo (
2 RTTs):asyncpg's connection pool issuesSELECT pg_advisory_unlock_all(); CLOSE ALL; UNLISTEN *; RESET ALL;as a second round trip on everypool.release(). pgdorm(1 RTT) keeps pooled connections clean by construction: no raw SQL execution, no session-mutating functions inpg.func(), transaction-scopedlocal_settings=, and immediate discard of non-idle connections on drop — so idle checkouts never pay aRESET ALLround trip.
Contender implementations#
Every tab below is AST-extracted directly from bench/adapters/ — zero hand-copied snippets.
pgdorm 0.10.0 (pgdorm-wire (Rust)) · 1 RTT · 43.5M instr · 6.76 ms · pgdorm_adapter.py
SQLAlchemy 2 2.1.9 (asyncpg) · 3 RTTs · 259.9M instr · 24.06 ms · sqlalchemy_adapter.py
SQLModel 0.0.50 (asyncpg) · 3 RTTs · 307.0M instr · 25.02 ms · sqlmodel_adapter.py
SQLDataclass 0.4.3 (psycopg3 (sync)) · 3 RTTs · 129.8M instr · 13.91 ms · sqldataclass_adapter.py
Django ORM 6.1.3 (psycopg3) · 1 RTT · 214.7M instr · 16.20 ms · django_adapter.py
Tortoise ORM 1.1.9 (asyncpg) · 2 RTTs · 365.0M instr · 25.60 ms · tortoise_adapter.py
Piccolo ORM 1.39.0 (asyncpg) · 2 RTTs · 390.0M instr · 24.57 ms · piccolo_adapter.py
Peewee 4.5.3 (psycopg3) · 1 RTT · 268.4M instr · 20.75 ms · peewee_adapter.py