Where pgdorm Does Not Win (Honest Trade-Offs)#
← All benchmarks · Related field note: Field Note 1 · Unit of Work & Identity Map
Single-database specialization and zero-state purity are real engineering choices — not magic free lunches. Every trade-off below is measured directly in this benchmark suite on live PostgreSQL 18+.
1. Repeated-PK lookups inside one transaction (Workload 13 · Identity Map Reads)#
When multiple layered service helpers inside one request transaction call get_by_pk() for the same rows, ORMs with a session-scoped Identity Map (SQLAlchemy 2 and SQLModel) hit PostgreSQL once per entity and serve repeat lookups from RAM in 0 RTTs — beating stateless pgdorm by ~2.6× on CPU instructions and ~2.7× on wire RTTs.
- Why
pgdormmakes this trade-off: No hidden session cache means zero stale-object bugs, zero implicit flushes, and predictable__slots__memory in long-running workers. - Idiomatic
pgdormremedy: Load the needed rows once at the handler boundary (in_any(ids)in 1 RTT) and pass the slotted objects explicitly.
2. Un-prepared ad-hoc single-row queries on 0 ms localhost (Workload 12 · Point Lookups, Workload 1 · Multi-Stmt Tx)#
When building fresh ad-hoc queries for tiny 1–4 row operations on a 0 ms localhost link, compiling a fresh Python AST across PyO3 into Rust IR + SQL + ShapeHash costs more client CPU than ultra-lightweight single-table ORMs:
- On Workload 12 · Point Lookups, lightweight peers match or beat un-prepared
pgdormon client CPU; pre-compiling once withpg.prepare()cutspgdorm's CPU roughly in half. - On Workload 1 · Multi-Stmt Tx, ad-hoc
pgdormretires slightly more client instructions (2.6M) than Tortoise (1.7M) and Peewee (1.9M), whilepg.prepare()dropspgdormto977kin1RTT vs4–5RTTs.
3. Server-side JSONB offloading (Workload 9 · Nested JSON API)#
Using pg.lateral_jsonb() + pool.json() cuts Python client CPU dramatically and drops nested payloads to 1 RTT, but shifts JSONB aggregation work onto the PostgreSQL server (Server ms rises, so combined Client + PG total instructions can be close to lightweight peers that hydrate in Python). On CPU-bound PostgreSQL primaries with abundant stateless web workers, a 2-RTT split_load() + client serialization can leave more headroom on the database server.
4. Native Rust memory outside Python tracemalloc (Workload 6 · PG ↔ Polars, Workload 10 · Reverse ETL)#
pgdorm's tiny Python peak heap (8.7 KiBexport /7.0 KiBingest) proves zero Python row allocation, while Arrow column arrays and the temporaryCOPYdecode buffer live in native Rust memory (compact and GC-free, but outside Python'stracemalloccounter).- On Workload 10 · Reverse ETL,
COPY FROM STDINtakes 2 true network turnarounds (5RTTs total vs4RTTs for sync peers) in exchange for much lower client CPU and peak Python heap (81.6 KiB).
5. SQL shape parity when peers opt into ANY (Workload 2 · Bulk Insert)#
Several peers already achieve 1 insert SQL shape across varied batch sizes via driver-level pipelined executemany. On IN lookups, peers default to variable-length IN ($1, ..., $N) (5 shapes in the default audit), though PostgreSQL squashes IN lists inside pg_stat_statements and SQLAlchemy users can explicitly opt into any_(). pgdorm enforces UNNEST and = ANY($1) unconditionally at compile time.