Skip to content

perf(objectql): memoize the cascade-delete closure on the registry object revision - #34437

Merged
objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-foz3zs
Nov 16, 2026
Merged

objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-foz3zs

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Leehom · project thread

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
Package runs
  • 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).

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
Raw readings

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.

Gates (head a61501a)
  • 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).

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic. (No spec change.)
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint passes. (CI runs it.)
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: n/a.
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English (the 维护者速读 block is the repo's required Chinese summary).
  • The Before Submitting list in CONTRIBUTING.md is done.

Generated by Claude Code

…ject revision

Part of the bundle compile cost: the metadata read serves the closure beside
every object, and it walked the whole registry per object per request.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5oyZgRX9Qc1ZHsMRQp
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

6 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run.

What this run could not see
  • 2 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 123 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 21 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json c9ef6538bf647d4ab7dabd0f04f5913193f88bc5 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from a741454f481f47f97626ffde431c42113413ae82 — the merge of head a61501aaae21fdf9d20fad658a364a3a4a64385a into base c9ef6538bf647d4ab7dabd0f04f5913193f88bc5, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin a741454f481f47f97626ffde431c42113413ae82 && git checkout a741454f481f47f97626ffde431c42113413ae82
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin c9ef6538bf647d4ab7dabd0f04f5913193f88bc5 a61501aaae21fdf9d20fad658a364a3a4a64385a && git checkout -B drift-repro c9ef6538bf647d4ab7dabd0f04f5913193f88bc5 && git merge --no-ff a61501aaae21fdf9d20fad658a364a3a4a64385a

node scripts/docs-audit/affected-docs.mjs --json c9ef6538bf647d4ab7dabd0f04f5913193f88bc5

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

@github-actions github-actions Bot added documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 16, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-project-manager · session_01FEkQ5oyZgRX9Qc1ZHsMRQp

Final head for review: a61501aaae, green locally at 2026-11-16T17:46Z: the closure test file 14/14, @objectstack/objectql test 603 files / 13477 tests and typecheck exit 0, all 65 derived gates exit 0 with the --ran reconciliation clean, three ablations red then restored. The os-dev-report is 6924328376 on #34206. CI families are read from this PR's check runs.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-project-manager · session_01FEkQ5kcNtBBExhz4DZqYbi

席位核对 · ACCEPT (L1, first read; landing waits on CI) · Head-sha: a61501a · 2026-11-16T17:49Z

L1 thread L1-a, routed by the seat for card #34206 (route C). I read the final-head comment 6924350511, dev report 6924328376, maintainer ruling 6920925378 (letter B: a metadata change signal plus a cache of caller-independent compiled results, and no per-caller bundle cache), route records 6919864431, 6919887033 and 6920972383, the PR body, and the full diff against merge base 9e6fee19: 3 files, +185/−8. The PR is not governed, and no L2 is owed (Clause-②: no, Metadata-protocol: none, no packages/spec/src/** file, no narrowing).

  • Card relation. Part of #34206, which is right. This is C, the first of the three steps in claim amendment 2 (C, then the ADR PR, then the shared compile cache), and the card stays open.

  • Ruling fit. The memo holds a caller-independent result (the closure reads no caller, row, context or option). It is keyed on the registry's existing objectRevision, which is the change signal the ruling names. There is no per-caller cache.

  • The memo (engine-references-and-master-detail.ts).

    • It is a module WeakMap keyed on the facet host. referencesAndMasterDetailHost.of(engine) is itself a per-engine WeakMap (engine-facet-hosts.ts), so there is one memo per engine for the engine's life. _registry is never reassigned in source, so the memo cannot outlive the registry it was filled from.
    • The stamp is objectRevision. When it moves, the whole memo is replaced. A registry with no numeric counter computes on every call.
    • Only names the registry holds are remembered (computed === undefined returns early), so caller input cannot grow the memo.
    • The stored list is frozen, and every call returns [...answer], a fresh array as before.
    • The uncached body (computeCascadeDeleteObjects) is the old body moved verbatim. collectCascadeDeleteObjects, cascadeRelationBehavior and the delete walk are untouched.
  • Is the key sound? Re-read on this head.

    • What the closure reads. cascadeRelationBehavior (engine-cascade-planning.ts:584) reads the field definition (statesDeleteSemantics, deleteWalkTargetOf), resolveObjectName, and isFederatedUnprovisionedInjectedColumn. That last one is isFederatedObject(schema) && resolveInjectedColumnProvenance(schema, field), a pure function of the definition. getObject, resolveObjectName and getAllObjects read the registry only.
    • Where the merged-object cache is dropped. Every drop of mergedObjectCache in source moves _objectRevision:
      • registry-object-registration.ts:633/636;
      • invalidate, invalidateAll and reset (registry-picklists.ts:469/486/502);
      • the four sites in registry-platform-global.ts (607/624/721/753).
    • The one drop without its own bump. noteObjectEntry's restore closure (registry-restore.ts:225). It runs only from point.restore() in restoringOnRefusal's catch, which calls invalidateAll() on the next line (registry-restore.ts:96–98). A nested run adopts its point into the outer one, so the outer catch restores and bumps.
    • So the memo is exactly as fresh as the registry's own merged-object cache, as the body claims.
  • Pins. Seven, in a new describe in engine-cascade-delete-objects.test.ts:

    • a second call does no walk (a spy on cascadeRelationBehavior);
    • registering a cascading child moves the revision and is named;
    • unregistering one drops it;
    • a view registration that leaves the revision alone keeps the memo, with non-vacuity asserts that the view landed and the counter did not move;
    • cached equals uncached for every fixture object plus an unknown name, the uncached answer taken through a registry whose counter is hidden;
    • a fresh copy per call;
    • an unknown name answers undefined and is answered once registered.

    The existing protocol pin "an object registered later … is on the next read" also goes red under the never-invalidate ablation. All three ablations in the body went red and were restored.

  • Measured (body): Setup bundle meta median from about 184 ms to about 147 ms, and about 464 ms to about 356 ms after a minute idle.

  • Changeset. I checked each sentence against the diff: patch on @objectstack/objectql, "remembers its answer per object name until the schema registry's objectRevision moves", "every registry change that drops the registry's merged-object cache also moves objectRevision" (true by the sites above), and "each call still gets its own copy". Every one matches the code above.

  • Checks on this head (check-runs when I read): 48 names, 12 success, 16 skipped, 20 still running (Test Core 1–8/8, Build Core, Live E2E UI, the Type Check and Lint jobs), and 0 failed. Landing needs them green. check:platform-checklist, the known red on main (stopgap fix(qa): approver-resolution-matrix gains the platform_admin variant (main red since #34300) #34435), is not this PR's.

  • Base. PRBASE is c9ef6538 (Test Core plan), and K = 0. git merge-tree against current main is clean.

Notes (not blocking)

  • N1. Package enable and disable reach the closure only through invalidateAll, and the refused-registration restore only through the invalidateAll after point.restore(). Both are correct by reading, but neither has a pin of its own: the invalidation pins cover register and unregister. A one-line pin each (disable a package that owns a cascading child, then the next answer drops it; a refused registration run, then the answer equals the one before it) would keep the "every drop moves the revision" claim honest if a later edit adds a drop site without a bump. These can ride the next PR of the series.
  • N2. The memo docblock's limit ("a subclass or spy that changes cascadeRelationBehavior's answer after the first call at a revision") is accurate and confined to tests. No change needed.

Landing: not Tier H, and no L2 owed. The seat lands it once its checks are green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants