Speed · The Plain Web Stack · diadem.fun
The Plain Web Stack8 / 15

Speed

An ORM costs time: validation, conversion, objects for every row. The question is how much. bench/overhead.ts in sqlite-zod-orm runs every operation twice on the same data, once through the library and once as hand-written bun:sqlite statements. It reports the library's speed as a percentage of the plain version, measured in the same run so that machine load cancels out.

Operation (10,000 rows, default options) 4.2.0 4.2.2
get(id) 12% 91%
select().where() range 9% 77%
.with() one level 10% 69%
update(id) 3% 58%
read and update one row (a game tick) not measured 74%
change a field by assignment 2% 62%
insert 7% 35%
upsert 4% 10%
How the gains were made:
  • Zod parsers and per-table plans are built once, not on every call.
  • Rows are decoded only for the columns that need it.
  • Statements per update went from three to two.
  • SQL text and query plans are cached per shape. One further round of changes did not measure faster: insert ×0.82 and upsert ×1.00, against run-to-run noise of about ±15%. It was not released.

Note: upsert and insert are still the slowest paths. If your app inserts tens of thousands of rows per second, batch them with insertMany (61% of plain SQL) or write those statements directly with db.raw. Next: chapter 9, limits.