Skip to content

perf(orm): add the SQLite ORM A/B benchmark and report - #105

Merged
Antruly merged 2 commits into
masterfrom
perf/orm-overhead
Nov 27, 2026
Merged

Antruly merged 2 commits into
masterfrom
perf/orm-overhead

Conversation

@Antruly

@Antruly Antruly commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Part of #95. Parent: #88. Do not close #95 yet: this supplies the SQLite A/B measurements; the fixed-runner gate, MySQL/PostgreSQL and p95 are still open.

What changed

  • New bench/orm/bench_orm.cpp — real SQLite A/B comparison, same client and connection:
    • point lookup, 100-row read, insert, update, remove: equivalent hand-written SQL vs ORM;
    • SQL construction and row mapping measured separately;
    • startup SQL/parameter equivalence check for every pair;
    • raw and ORM arms alternate so machine drift is not attributed to one side.
  • New bench/orm/run_orm_overhead.sh — 3-round driver, fresh timestamped result directory, raw logs, TSV/JSON, per-run and aggregate ORM-vs-raw overhead, failure paths.
  • bench/CMakeLists.txt target guarded by DB + ORM.
  • bench/orm/README.md methodology, result directory layout, field definitions, limitations and the 8.7 post-optimization report.

No src/ behavior is changed by this PR; the ORM optimizations were #103/#104.

Result (3 rounds, SQLite, development machine)

case          unit  raw p50  ORM p50  p50 extra  raw p99  ORM p99  p99 extra  gate
pk            call  6.25299  6.547     +4.70%    9.11902  9.90204  +8.59%    target_met
find_all100   call  39.248   42.643    +8.65%    48.337   54.675   +13.11%   target_met
update        call  963.477  969.465   +0.62%    1511.64  1538.22  +1.76%    target_met
insert        call  975.899  976.125   +0.02%    1557.91  1429.66  −8.23%    target_met
remove        call  968.644  972.337   +0.38%    1463.41  1667.15  +13.92%   target_met

build_select  query 0.124449 1.01252   +714% (absolute ~0.9 us)
map_rows      row   0.02629  0.052171  +98%  (absolute ~52 ns/row)

This is not a release gate: the machine is a powersave, unbound development machine with loadavg ~3.0; there are only 3 rounds, no p95, and only SQLite. A fixed-runner, performance-governor run is required before #95 can close.

Verification

bench/orm/run_orm_overhead.sh --reps 3 ...  -> rc 0
3 × run-01..03 logs + summary.txt + summary.json
python3 -I -m json.tool summary.json        -> ok
bad URL                                     -> exit 1
missing binary/build dir                    -> exit 2
consecutive calls                           -> distinct directories, no overwrite
bash -n run_orm_overhead.sh                 -> ok

Unverified

  • MySQL/PostgreSQL/ODBC/Windows/macOS numbers.
  • Connection pool 1/4/16, concurrency 1/16/64, transactions, async, BLOB/large results, field-count scaling, allocations/CPU counters, p95.
  • Fixed-runner release gate.

Add a SQLite A/B benchmark for point lookups, 100-row reads, insert/update/remove, SQL construction and row mapping, with a non-overwriting driver script and a documented gate report. Current development-machine point-select A/B exceeds the hard gate; the report states that explicitly.
Update the benchmark report with the three-round SQLite result after the ORM SQL-shape and validation caches: all end-to-end p50/p99 cases are within the 15% target on this machine, while the fixed-runner and MySQL/PostgreSQL caveats remain.
@Antruly

Antruly commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Local review before merge: three-round SQLite A/B completed with raw/ORM SQL equivalence checked; all end-to-end p50/p99 cases are within the 15% target on this development machine, the JSON validates, bad-input exit codes are 1/2, and consecutive runs do not overwrite. This is not a fixed-runner release gate; MySQL/PostgreSQL, p95, pool/concurrency and async latency remain open.

@Antruly
Antruly merged commit 538350b into master Nov 27, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance] 数据库同步/异步与 ORM 性能基准和回归门禁

1 participant