Repository navigation
Commit d18d54b
perf(objectql): memoize the cascade-delete closure on the registry object revision (#34437)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1X7M2UeBw2UaWzE4U5gbL4AH)_
Part of #34206 (route C, the first of three changes: C, then the ADR PR,
then the shared compile cache, per ruling 6920925378 and claim amendment
2 6920972383). The card stays open after this lands.
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
改了什么:「删除时会连带删掉哪些对象」这份清单,以前每读一个对象就把全部对象扫一遍重算;现在按对象注册表的版本号记住,版本号不变就直接给答案。
- 为什么改:控制台每次打开应用都要读整包元数据,包里每个对象都重算一次这份清单。Setup 包重复请求的 meta 中位数从约 184 ms
降到约 147 ms,隔一分钟再开从约 464 ms 降到约 356 ms。
- 风险与回滚:只有一种风险,就是对象变了而版本号没动、清单变旧;已核对注册表里每个让对象缓存失效的地方都会推进版本号。回滚就是撤掉这一个
PR,行为回到每次重算。
- 先看:`packages/objectql/src/engine-references-and-master-detail.ts` 末尾的
`getCascadeDeleteObjects` 与 `cascadeDeleteObjectsMemo`
说明块;`packages/objectql/src/engine-cascade-delete-objects.test.ts` 末尾新增的
describe。
- 两分钟验证:`pnpm --filter @objectstack/objectql exec vitest run
--maxWorkers=2 src/engine-cascade-delete-objects.test.ts`,预期 14 个测试全绿。
- 需要你做的:无,席位落地。
## What changes
`ObjectQL#getCascadeDeleteObjects` (the objects a delete of a record can
cascade into, which the metadata read serves beside every `object` item
as `cascadeDeleteObjects`) is memoized per engine on the schema
registry's existing `objectRevision`.
- Key: the object name as asked, inside one memo per engine stamped with
the revision it was filled at. A moved revision replaces the whole memo.
A registry without the counter (a test double) declines the memo and
every call computes, as before.
- Value: the computed list, frozen; every call returns its own copy, so
a caller that edits its list cannot change the next caller's answer.
- A name the registry does not hold answers `undefined` and is not
remembered, so the memo grows with the registered objects and never with
what callers ask.
- Only `packages/objectql/src/engine-references-and-master-detail.ts`
changes in the runtime. The rule (`collectCascadeDeleteObjects`,
`cascadeRelationsInto`, `cascadeRelationBehavior`) is untouched, and so
is the delete walk, which still reads the rule fresh.
## Why
The card's profile and the earlier report (6919782135) put the closure
at about 47 ms of a Setup bundle call: an app bundle reads every object
it names, and each read walked every registered object. The walk reads
the registered object set and nothing else, and the registry already
keeps a counter that moves on every change to that set, which the
roll-up summary index and the record-currency parent lock already key
on.
### Closure inputs, re-verified on 9e6fee1 before the first edit
- `resolveObjectName` and `getObject` read the registry's object index
(`resolveObjectKey`, `resolveObject`); `getAllObjects` reads the merged
objects.
- `cascadeRelationBehavior` reads one field definition
(`statesDeleteSemantics`, `deleteWalkTargetOf`), resolves its target
through the same index, and asks
`isFederatedUnprovisionedInjectedColumn`, which reads only the schema it
is handed (`isFederatedObject` and `resolveInjectedColumnProvenance` are
pure functions of the definition).
- Package enablement reaches the merged objects only through the fold
(`withholdDisabledExtensions`), and `enablePackage` / `disablePackage`
both call `invalidateAll`, which moves the revision.
- Every site that drops the registry's merged-object cache moves
`objectRevision`: `registerObject`, `unregisterObject`,
`unregisterObjectsByPackage`, `removeObjectOverlay`,
`withdrawObjectExtension`, `invalidate`, `invalidateAll`, `reset`. The
refused-registration restore (`noteObjectEntry`'s restore closure) drops
the cache without a bump itself, but its only caller,
`restoringOnRefusal`, runs it inside a synchronous registration and
calls `invalidateAll` right after `point.restore()`, so the revision
moves there too. The earlier report's note on that restore is answered
by this.
- No row, no caller context, no datasource posture and no per-call
option feeds it.
## Tests
Seven pins in
`packages/objectql/src/engine-cascade-delete-objects.test.ts`, a new
top-level `describe` in the closure's existing harness file:
- a second call at the same revision does no walk
(`cascadeRelationBehavior` spy not called) and answers the same list;
- invalidation: registering a cascading child moves the revision and the
next call names it; unregistering one drops it;
- control: a registry change that leaves the object revision alone (a
`view` item) keeps the memo (no walk) and the answer stays right, with
non-vacuity asserts that the view landed and the counter did not move;
- cached equals uncached for every fixture object plus an unregistered
name, the uncached reading taken through the same facet over a registry
whose counter is hidden;
- each call gets its own copy;
- an unregistered name answers `undefined`, and its later registration
is answered.
Ablations (`scripts/ablation-replace.mjs`, each restored to the HEAD
blob `ba03b08f`, `git diff HEAD` empty after each):
| mutation | red pins |
|:--|:--|
| never invalidate (`memo.revision !== revision` dropped from the refill
test) | 3: both invalidation pins and the existing protocol pin "an
object registered later ... is on the next read" |
| no memo (the lookup always misses) | 2: the second-call pin and the
control |
| no copy (the frozen list returned as is) | 1: the copy pin |
<details><summary>Package runs</summary>
- `pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2
src/engine-cascade-delete-objects.test.ts`: Test Files 1 passed, Tests
14 passed.
- `pnpm --filter @objectstack/objectql test`: Test Files 603 passed
(603), Tests 13477 passed (13477), exit 0.
- `pnpm --filter @objectstack/objectql typecheck`: exit 0;
`check:test-typecheck: OK`, 39 files / 233 errors / 64 pinned signatures
held in `test-typecheck-debt.json` (unchanged).
</details>
## Acceptance notes
- Readings for the card's three cases plus first call, below. The Setup
bundle moves; the showcase app bundle (few objects) does not move beyond
noise, which is what a per-object saving predicts.
- The "reload more than one minute later" case is still dominated by the
expired overlay row cache (about 219 queries, `db` 65 to 87 ms) and the
full recompile; that is the shared compile cache's job (the third
change), not this one.
- Not measured: hosted staging; cloud#4563 acceptance 1 is judged there.
## Verification
Same box, same build, `pnpm dev -- --fresh` showcase, seeded admin,
`X-OS-Debug-Timing: 1`, `meta` member of `Server-Timing` in ms. "Before"
is this branch with only `engine-references-and-master-detail.ts`
restored to `origin/main` 9e6fee1 and objectql rebuilt (dist checked: 0
hits of the memo's name, 4 after the restore). Shared box: other agents'
work may have been running.
| case | Setup before | Setup after | showcase_app before | showcase_app
after |
|:--|:--|:--|:--|:--|
| immediate repeat, 6 calls (median, range) | 183.5 (165–201) | 146.6
(142–204) | 68.4 (66–80) | 70.2 (64–107) |
| 304 with If-None-Match, 6 calls | 169.6 (158–178) | 134.8 (117–153) |
76.4 (68–101) | 71.0 (65–78) |
| reload 65 s after the previous call, 3 calls | 464 (364–481) | 356
(330–366) | 114 (100–114) | 83 (77–92) |
| first call after a fresh boot, 3 boots | 889 (822–954) | 738 (664–781)
| n/a | n/a |
<details><summary>Raw readings</summary>
Before, Setup: repeat 201.02 / 187.39 / 183.25 / 183.83 / 165.43 /
170.27; 304 168.97 / 158.21 / 167.23 / 171.11 / 170.15 / 177.99; reload
464.12 / 480.78 / 363.73; first call 953.69 / 889.24 / 822.17.
After, Setup: repeat 157.06 / 143.86 / 204.05 / 148.84 / 144.26 /
142.43; 304 152.45 / 153.17 / 118.51 / 117.11 / 150.09 / 119.56; reload
329.69 / 365.96 / 355.66; first call 663.82 / 780.87 / 737.67.
Before, showcase_app: repeat 65.54 / 66.51 / 71.57 / 68.52 / 68.19 /
79.83; 304 77.19 / 68.62 / 75.6 / 67.98 / 101 / 77.63; reload 114.31 /
114.27 / 99.81.
After, showcase_app: repeat 73.99 / 106.76 / 63.87 / 66.49 / 64.4 /
77.97; 304 70.8 / 64.81 / 75.38 / 71.17 / 77.53 / 65.38; reload 82.84 /
92.1 / 77.31.
</details>
<details><summary>Gates (head a61501a)</summary>
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack`: 65 commands derived for this diff (49 by
path, 9 by change kind, 9 whole-tree); all 65 run locally, each exit 0,
recorded as `COMMAND :: exit CODE`.
- `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack
--ran FILE`: "65 derived famil(ies) accounted for — 65 run, 0
NOT-MEASURED (a DERIVED zero — all 65 recorded an exit code and none of
them is 3)", exit 0.
- `node scripts/check-nul-bytes.mjs`: exit 0.
- `git merge-tree --write-tree origin/main HEAD` against `origin/main`
c9ef653: clean (exit 0); `origin/main` has not touched the closure
files or the registry since the base. No open pull request touches the
three files (39 open heads read; two old ones whose history this
checkout lacks were read through their file lists, both empty).
- Families CI owns (the type-check lanes, Build Core, Test Core shards,
the artifact rosters and the repo-wide `pnpm lint`) are read from this
PR's check runs, not re-run here.
- Dogfood battery: not owed (no `!` in the title, no `(narrowing)` arm).
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(No spec change.)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes. (CI runs it.)
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: n/a.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English (the 维护者速读 block is the
repo's required Chinese summary).
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5oyZgRX9Qc1ZHsMRQp)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 6a7403b commit d18d54b
3 files changed
Lines changed: 185 additions & 8 deletions
File tree
- .changeset
- packages/objectql/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
638 | 638 | | |
639 | 639 | | |
640 | 640 | | |
641 | | - | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
642 | 648 | | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
650 | 667 | | |
651 | 668 | | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
0 commit comments