Skip to content

fix(metadata): index top-level names so reference resolution no longer scales quadratically - #604

Merged
dmealing merged 5 commits into
mainfrom
fm/mo-ref-index-fix
Nov 18, 2026
Merged

dmealing merged 5 commits into
mainfrom
fm/mo-ref-index-fix

Conversation

@dmealing

@dmealing dmealing commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • Reference resolution in the TypeScript, Python and C# loaders now uses a per-root top-level name index (first match wins, same ordering and errors) instead of scanning every top-level object per lookup, with a structure-epoch counter so a changed root rebuilds the index and never serves a stale result; super resolution, Python's extends resolver and the overlay/merge target scans reuse the same index. No behavior change and no version bump — metamodel conformance and registry corpora pass, and canonical serialization of a 20x model is byte-identical before and after in all three ports.
  • C# adds a thread-static ResolutionKeyProbe and per-thread rebuild counter (visible only to the Conformance test project via InternalsVisibleTo) so regression tests count key calls and index rebuilds at 1x/5x/10x rather than wall-clock; TypeScript package/fileDefaultPackage became accessors that re-key the node, and the index falls back to the linear scan when a root has a parent/super or overrides child accessors.
  • Adds scripts/bench-load/ (model generator, warm-load drivers for all three ports, run.sh, README) and a ci-lane-map rule marking scripts/bench-load/* as NONE (run by hand, no test lane); one CHANGELOG line under [Unreleased]/Fixed.

Benchmark: 9 warm loads each, median. The machine was busy, so wall-clock is noisy — the deterministic count tests are the regression gate. Python and C# still grow slightly faster than linearly, but a profile shows no remaining hot spot in the lookup.

port 1x ms before -> after 20x ms before -> after 20x/1x growth before -> after peak RSS at 20x before -> after
typescript 9.8 -> 12.1 633.3 -> 120.4 64.6x -> 10.0x 332 -> 395 MiB
python 19.4 -> 19.1 1449.6 -> 747.6 74.7x -> 39.1x 80 -> 79 MiB
csharp 10.7 -> 10.1 340.2 -> 232.2 31.8x -> 23.0x 173 -> 176 MiB
Validation

Risk Assessment

✅ Low: A semantics-preserving indexing change with correct epoch invalidation on every real mutation path in all three ports, behavior-based regression tests with independent oracles, and both earlier-round fixes verified present in the final tree; no reachable wrong-result or staleness path found.

Testing

Exercised the three ports this change touches, live: the deterministic work-count regression tests (resolutionKey calls per top-level node not growing at 1x/5x/10x, bounded index rebuilds, and never-stale lookups after node add/re-key/merge) passed in TS (63 tests), Python (12) and C# (9), and the real TS and Python loaders loaded a throwaway 20x fitness model with zero errors through the shipped bench drivers, TS producing a valid canonical serialization. Wall-clock medians were captured but treated as noise per the intent; the count tests are the gate and all are green. Baseline broad regression is the configured command's passing run at this commit. No findings.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
TypeScript loader resolves references via the index on a generated 20x fitness model (count gate + live warm-load through the built dist package) ✅ pass live bun test test/top-level-index.test.ts test/naming-refs.test.ts test/super-resolve.test.ts (63 pass, includes per-node key-call non-growth at 1x/5x/10x and never-stale lookups after add/re-key/merge)…
Python loader resolves references via the index on a generated 20x model (count gate + live warm-load) ✅ pass live uv run pytest tests/loader/test_top_level_index.py -q (12 passed, covering resolution_key calls per top-level node not growing at 1x/5x/10x, index rebuild bounds, and never-stale after node add/remo…
C# loader reference resolution stays linear and never stale (deterministic count tests via the thread-static probe) ✅ pass live dotnet test MetaObjects.Conformance.Tests --filter "FullyQualifiedName~TopLevelIndex" — Passed! Failed: 0, Passed: 9, Skipped: 0, Total: 9 (592 ms), including ResolutionKey-call non-growth and Rebui…
Evidence: TS warm-load of 20x model (real dist loader)
{"port":"typescript","loads":5,"median_ms":507.1,"peak_rss_mib":327} — zero load errors; canonical serialization of the 20x tree written and non-empty.
Evidence: Python warm-load of 20x model
{"port":"python","loads":5,"median_ms":1758.4,"peak_rss_mib":82} — zero load errors.
Evidence: C# deterministic count tests
Passed! - Failed: 0, Passed: 9, Skipped: 0, Total: 9, Duration: 592 ms - MetaObjects.Conformance.Tests.dll (net8.0), filter FullyQualifiedName~TopLevelIndex.
Evidence: TS focused index/naming/super-resolve tests
bun test v1.3.14: 63 pass, 0 fail, 108 expect() calls across top-level-index, naming-refs, super-resolve test files.
Evidence: Python top-level-index tests
............ [100%] 12 passed in 0.89s (tests/loader/test_top_level_index.py).

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
TypeScript loader resolves references via the index on a generated 20x fitness model (count gate + live warm-load through the built dist package) ✅ pass live bun test test/top-level-index.test.ts test/naming-refs.test.ts test/super-resolve.test.ts (63 pass, includes per-node key-call non-growth at 1x/5x/10x and never-stale lookups after add/re-key/merge)…
Python loader resolves references via the index on a generated 20x model (count gate + live warm-load) ✅ pass live uv run pytest tests/loader/test_top_level_index.py -q (12 passed, covering resolution_key calls per top-level node not growing at 1x/5x/10x, index rebuild bounds, and never-stale after node add/remo…
C# loader reference resolution stays linear and never stale (deterministic count tests via the thread-static probe) ✅ pass live dotnet test MetaObjects.Conformance.Tests --filter "FullyQualifiedName~TopLevelIndex" — Passed! Failed: 0, Passed: 9, Skipped: 0, Total: 9 (592 ms), including ResolutionKey-call non-growth and Rebui…
  • scripts/ci-local.sh --affected --strict-toolchains
  • Baseline: scripts/ci-local.sh --affected --strict-toolchains (already ran and passed at target commit 70e60e090; not re-run, no source changes made this turn)
  • cd server/typescript/packages/metadata && bun test test/top-level-index.test.ts test/naming-refs.test.ts test/super-resolve.test.ts
  • cd server/python && uv run pytest tests/loader/test_top_level_index.py -q
  • cd server/csharp && dotnet test MetaObjects.Conformance.Tests --filter "FullyQualifiedName~TopLevelIndex"
  • Live warm-load: python3 scripts/bench-load/gen-model.py 20 $DEV_SCRATCH/mobench*/model20 && node scripts/bench-load/ts-load.mjs <model> 5 --canonical <out>
  • Live warm-load: python3 scripts/bench-load/py_load.py <model20> 5
  • Teardown: rm -rf /mnt/scratch/mobenchiuyo; git status --porcelain clean
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…lution is linear

Reference resolution scanned every top-level object per lookup, so load time grew with the
square of the model. Each root now keeps a name index (first match wins, same errors),
invalidated when its top-level nodes change, and reused by super resolution and the overlay
and merge target scans. Adds per-port count-based regression tests, the scripts/bench-load
benchmark, and a CHANGELOG line. No behaviour change: canonical output of a 20x model is
byte-identical before and after in all three ports.
@dmealing
dmealing merged commit 28e4aca into main Nov 18, 2026
10 checks passed
@dmealing
dmealing deleted the fm/mo-ref-index-fix branch November 18, 2026 23:59
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.

1 participant