Repository navigation
Commit 777877d
test(qa): SQL performance M0 baseline — SQLite and PostgreSQL at 100k and 1M rows (#33662)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DWLrF6ZURGN6BVpSbuDyHTg)_
Fixes #33633
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:在 `packages/qa/dogfood/bench/sql-perf/` 加了一套 SQL 性能基准(固定测试应用 +
HTTP 基准脚本 + "现状 SQL 对比目标 SQL"脚本),只测量,不动任何产品代码。
- 为什么改:SQL 性能专题(#33631)的 M0 要求先量后修:在 SQLite 和 PostgreSQL 上、10 万和 100
万行规模下给出每条路径的耗时和 SQL 条数,排出 M2 的优先级。排序清单已贴在 #33631。
- 风险与回滚:无运行时风险——私有包里的脚本与夹具,不发布、不进测试套件;回滚即删除该目录并还原 dogfood 的 tsconfig 一行。
-
先看:`packages/qa/dogfood/bench/sql-perf/bench.mjs`(场景定义与计数方式)、`micro.mjs`(每个"预期收益"数字的来源)、`app/objectstack.config.ts`(数据形状)。
- 两分钟验证:`pnpm --filter '@objectstack/cli...' build` 之后跑 `node
packages/qa/dogfood/bench/sql-perf/bench.mjs --dialect sqlite --scale
1000 --iterations 3`,预期约 1 分钟内打印 19 个场景并写出 `results/sqlite-1000.md`,其中
`cross_object_filter_large` 在此规模为 200、`cascade_delete_opportunity` 为 155
条 SQL。
- 需要你做的:在 #33631 的排序清单里挑出 M2 要立的卡。
## What changes
- `packages/qa/dogfood/bench/sql-perf/app/objectstack.config.ts` — the
fixture app: `bench_region` (20) -> `bench_account` (scale/100, private
OWD) -> `bench_opportunity` (scale/10, controlled_by_parent) ->
`bench_line_item` (scale, controlled_by_parent, lookup `bench_product`).
A default permission set gives a member `own` read on accounts, so the
member's reads compose the nested master chain.
- `bench.mjs` — boots the fixture with `os dev --no-watch` on SQLite
(`better-sqlite3` SqlDriver) or PostgreSQL, mints a member, writes one
template row per object through the API, stops the server, bulk-loads
the tables directly, runs `ANALYZE`, reboots and times 18 read scenarios
(admin and member) plus a cascade delete over HTTP. Per scenario: client
p50/p95, server total, and the exact SQL statement count from the `db`
mark of `Server-Timing` (`OS_SERVER_TIMING=true`); the admin's SQL text
from `X-OS-Debug-Timing: json`. Every phase has a deadline; the server
is torn down by process group.
- `micro.mjs` — on a seeded database, times the statement the engine
runs today beside the statement it could run (the "expected gain" column
of the ranked list), including two temporary-index pairs it drops again.
- `README.md` — how to run and read it.
- `packages/qa/dogfood/tsconfig.json` — `include` gains `bench/**/*.ts`,
so the fixture config is type-checked with the package. Vitest still
collects `test/**` only; nothing here runs in CI's test jobs.
The inventory, the baseline tables and the ranked list are on the epic:
#33631 (ranked-list comment). (Corrected after review#2, see the
correction comment on #33631.) Headline: R1 per-measure aggregation
filter loads every row into the app (PG 7.3 s at 1M). A conditional
aggregate does it in 0.14 s: that was `sum(case when … end)`, and PG
`FILTER (WHERE …)` measures the same. R2 an analytics dimension through
a lookup answers 500 above the bind limit on both dialects. R3 the
default sort column `created_at` has no index. On PG the index alone
takes the admin default page, as emitted today, from 229 ms to 0.9 ms at
1M. On SQLite it helps only together with R4: the chained page keeps its
plan, and the page goes 1.2–1.7 s to 0.09 ms only once the vacuous chain
is dropped. R5: 400 INVALID_FILTER at 100k (~2,000 matching
opportunities; ~20,000 at 1M).
## Tests
No product code changed, so no unit test; the deliverable is the harness
and its readings.
<details><summary>Benchmark runs (all four cells of the card's
matrix)</summary>
- SQLite 100k, SQLite 1M, PG 100k, PG 1M — every scenario measured; seed
1.2 s / 9.3 s / 3.7 s / 32.6 s. Runs were taken at `fc532017` and (PG
1M) `e78703bd`; `bench.mjs` and the fixture are byte-identical between
the two and the final head.
- Smoke at scale 1000: 19 scenarios, exit 0.
- Lock verdicts: `VERDICT command-exit 0` (100k pair), `VERDICT
batch-last-exit 0` (1M pair, both parts printed their `wrote … .json`
line), `VERDICT command-exit 0` (SQL pairs, both dialects).
</details>
## Acceptance notes
- PostgreSQL ran on a private cluster in the container (`fsync=off`,
`synchronous_commit=off` to speed the bulk load; reads are what is
timed). The box is shared with other agents: statement counts are exact,
milliseconds indicative.
- The member's SQL text is not shown (the server discloses
`X-OS-Debug-Timing-Detail` to an admin only); its statement count is
exact.
- Not covered by this fixture, so not measured: sharing grants
(`sys_record_share`), roll-up summaries, Turso remote, a network
database. They are in the ranked list as unmeasured items.
- Read-only inference, not reproduced, not filed:
`SharingService#buildReadFilter` reads at most 5000 `sys_record_share`
rows into an `id IN (…)`, so grants past 5000 look silently dropped
(fail-closed). Needs a share-seeding leg to measure.
- Location: the harness lives in the private `@objectstack/dogfood`
package because it needs `@objectstack/spec` (for `defineStack`), the
`os` binary and driver-sql's clients, all already dependencies there —
no lockfile change, no new package.
## Verification
<details><summary>Local gates at head (this PR's derived
families)</summary>
- `node scripts/pm/dispatch-gates.mjs --commands`: 46 families derived
from the diff; all 46 run and reconciled with `--ran` (46 derived, 46
run, 0 unrun). 43 exit 0.
- NOT MEASURED locally (environment, not the diff): `check:dts-closure`
(exit 1 — this worktree built the CLI closure with `OS_SKIP_DTS=1`, so
declaration files are absent), `check:dual-build-cjs-loads` (exit 3,
PREREQUISITE NOT MET — no full `pnpm build`),
`check-plugin-teardown-shape.mjs --self-test` (exit 3 — shallow clone
cannot reach its pinned positive-control commit). CI's full build runs
all three.
- `tsc -p` over the dogfood compiler options restricted to
`bench/**/*.ts`: exit 0, `objectstack.config.ts` in the program
(`--listFiles`).
- `eslint --no-inline-config packages/qa/dogfood/bench`: exit 0.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4d1QwJJ5KGZTThP4fnq)_
<!-- signed: domain:server#5 · os-elon-musk ·
session_016WV4d1QwJJ5KGZTThP4fnq -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 854d383 commit 777877d
5 files changed
Lines changed: 1029 additions & 1 deletion
File tree
- packages/qa/dogfood
- bench/sql-perf
- app
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
0 commit comments