Skip to content

fix(metamodel): derive general types and feature directions once per element - #2379

Merged
HuiJun merged 3 commits into
developfrom
fix/api-json-inherited-member-allocs
Nov 19, 2026
Merged

HuiJun merged 3 commits into
developfrom
fix/api-json-inherited-member-allocs

Conversation

@HuiJun

@HuiJun HuiJun commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

What and why

The API JSON export allocates far more on develop than on v0.12.1, and the inherited-member derived properties added in #1915 are where it goes: Type::input, Type::output and Type::directedFeature each read the direction of every effective feature of a type, and each of those reads walks the owner's general types.

Relation to #2377. #2377 memoizes structureOwnedFeatures and structureOwnedSupertypes for the same walk and is meant to land first. This branch has #2377 merged into it and carries no copy of those two memos; until #2377 is in develop, its commit shows in this diff. What this pull request adds on top, per element, in internal/semantic/metamodel:

  • the specialized general types (structureSpecializedGeneralTypes), served to the direction walk without a copy and to every other caller as a list of its own;
  • the direction of each effective feature (structureFeatureDirections), read once and shared by input, output and directedFeature.

No property is dropped or changed: the written document is byte-identical.

Benchmark: develop (5f3a2b3), #2377 (1236e9f), this branch

go test ./tests/export -run '^$' -bench WriteAPIJSON -benchtime 3x -count 6, compared with benchstat; both vs base columns are against develop. The allocation figures are exact; the timings were taken on a shared 8-vCPU machine and are noisy.

                                           │  develop.txt  │             pr2377.txt              │              this.txt               │
                                           │    sec/op     │    sec/op     vs base               │    sec/op     vs base               │
WriteAPIJSON/ISQAtomicNuclear/standard-8     1174.5m ± 47%   583.7m ± 13%  -50.30% (p=0.026 n=6)   742.0m ± 33%        ~ (p=0.394 n=6)
WriteAPIJSON/ISQAtomicNuclear/compact-8       618.4m ± 21%   563.7m ±  4%   -8.83% (p=0.004 n=6)   617.9m ± 10%        ~ (p=0.699 n=6)
WriteAPIJSON/SimpleVehicleModel/standard-8     5.169 ±  3%    2.102 ±  9%  -59.34% (p=0.002 n=6)    1.478 ±  6%  -71.42% (p=0.002 n=6)
WriteAPIJSON/SimpleVehicleModel/compact-8      5.848 ± 14%    2.134 ±  4%  -63.50% (p=0.002 n=6)    1.393 ±  8%  -76.17% (p=0.002 n=6)
WriteAPIJSON/then_after_members/standard-8    906.9m ± 11%   355.1m ± 11%  -60.85% (p=0.002 n=6)   200.1m ± 14%  -77.94% (p=0.002 n=6)
WriteAPIJSON/then_after_members/compact-8     857.4m ±  7%   382.0m ± 16%  -55.45% (p=0.002 n=6)   190.1m ± 19%  -77.83% (p=0.002 n=6)
geomean                                        1.605         764.9m        -52.34%                 574.3m        -64.21%

                                           │ develop.txt  │              pr2377.txt              │               this.txt               │
                                           │   output-B   │   output-B    vs base                │   output-B    vs base                │
WriteAPIJSON/ISQAtomicNuclear/standard-8     12.43Mi ± 0%   12.43Mi ± 0%       ~ (p=1.000 n=6) ¹   12.43Mi ± 0%       ~ (p=1.000 n=6) ¹
WriteAPIJSON/ISQAtomicNuclear/compact-8      5.243Mi ± 0%   5.243Mi ± 0%       ~ (p=1.000 n=6) ¹   5.243Mi ± 0%       ~ (p=1.000 n=6) ¹
WriteAPIJSON/SimpleVehicleModel/standard-8   24.41Mi ± 0%   24.41Mi ± 0%       ~ (p=1.000 n=6) ¹   24.41Mi ± 0%       ~ (p=1.000 n=6) ¹
WriteAPIJSON/SimpleVehicleModel/compact-8    8.373Mi ± 0%   8.373Mi ± 0%       ~ (p=1.000 n=6) ¹   8.373Mi ± 0%       ~ (p=1.000 n=6) ¹
WriteAPIJSON/then_after_members/standard-8   1.780Mi ± 0%   1.780Mi ± 0%       ~ (p=1.000 n=6) ¹   1.780Mi ± 0%       ~ (p=1.000 n=6) ¹
WriteAPIJSON/then_after_members/compact-8    664.2Ki ± 0%   664.2Ki ± 0%       ~ (p=1.000 n=6) ¹   664.2Ki ± 0%       ~ (p=1.000 n=6) ¹
geomean                                      4.987Mi        4.987Mi       +0.00%                   4.987Mi       +0.00%
¹ all samples are equal

                                           │  develop.txt  │              pr2377.txt              │              this.txt               │
                                           │     B/op      │     B/op       vs base               │     B/op      vs base               │
WriteAPIJSON/ISQAtomicNuclear/standard-8      276.3Mi ± 0%    252.0Mi ± 0%   -8.81% (p=0.002 n=6)   251.5Mi ± 0%   -8.98% (p=0.002 n=6)
WriteAPIJSON/ISQAtomicNuclear/compact-8       277.1Mi ± 0%    252.9Mi ± 0%   -8.73% (p=0.002 n=6)   252.3Mi ± 0%   -8.93% (p=0.002 n=6)
WriteAPIJSON/SimpleVehicleModel/standard-8   4872.3Mi ± 0%   1468.3Mi ± 0%  -69.86% (p=0.002 n=6)   913.1Mi ± 0%  -81.26% (p=0.002 n=6)
WriteAPIJSON/SimpleVehicleModel/compact-8    4846.8Mi ± 0%   1443.0Mi ± 0%  -70.23% (p=0.002 n=6)   887.8Mi ± 0%  -81.68% (p=0.002 n=6)
WriteAPIJSON/then_after_members/standard-8    830.6Mi ± 0%    310.9Mi ± 0%  -62.57% (p=0.002 n=6)   171.2Mi ± 0%  -79.39% (p=0.002 n=6)
WriteAPIJSON/then_after_members/compact-8     825.8Mi ± 0%    306.2Mi ± 0%  -62.93% (p=0.002 n=6)   166.5Mi ± 0%  -79.84% (p=0.002 n=6)
geomean                                       1.012Gi         484.0Mi       -53.31%                 337.0Mi       -67.48%

                                           │ develop.txt  │             pr2377.txt             │              this.txt              │
                                           │  allocs/op   │  allocs/op   vs base               │  allocs/op   vs base               │
WriteAPIJSON/ISQAtomicNuclear/standard-8      2.466M ± 0%   2.373M ± 0%   -3.77% (p=0.002 n=6)   2.375M ± 0%   -3.71% (p=0.002 n=6)
WriteAPIJSON/ISQAtomicNuclear/compact-8       2.527M ± 0%   2.434M ± 0%   -3.68% (p=0.002 n=6)   2.436M ± 0%   -3.62% (p=0.002 n=6)
WriteAPIJSON/SimpleVehicleModel/standard-8   16.093M ± 0%   5.561M ± 0%  -65.44% (p=0.002 n=6)   3.850M ± 0%  -76.08% (p=0.002 n=6)
WriteAPIJSON/SimpleVehicleModel/compact-8    16.207M ± 0%   5.675M ± 0%  -64.98% (p=0.002 n=6)   3.964M ± 0%  -75.54% (p=0.002 n=6)
WriteAPIJSON/then_after_members/standard-8   2805.5k ± 0%   965.3k ± 0%  -65.59% (p=0.002 n=6)   523.9k ± 0%  -81.33% (p=0.002 n=6)
WriteAPIJSON/then_after_members/compact-8    2814.0k ± 0%   973.9k ± 0%  -65.39% (p=0.002 n=6)   532.6k ± 0%  -81.07% (p=0.002 n=6)
geomean                                       4.839M        2.357M       -51.29%                 1.706M       -64.75%

Against #2377 alone, this branch takes allocs/op from 965.3k to 523.9k on then_after_members and from 5.561M to 3.850M on SimpleVehicleModel (standard form).

Where that leaves the two benchmarks against v0.12.1

allocs/op, standard form, the same benchmark run at each commit:

v0.12.1 before #1915 #1915 develop #2377 this branch
then_after_members 199k 276k 845k 2,806k 965k 524k
SimpleVehicleModel 2.08M 2.90M 5.19M 16.09M 5.56M 3.85M
then_after_members output 0.92 MiB not recorded not recorded 1.78 MiB 1.78 MiB 1.78 MiB
SimpleVehicleModel output 15.7 MiB not recorded not recorded 24.4 MiB 24.4 MiB 24.4 MiB

Both are now below what #1915 itself cost, but not back at v0.12.1: the document is 1.9 and 1.6 times the size it was then.

How it was verified

  • Same output: sysml -convert api-json built from perf(metamodel): memoize owned features and supertypes in the direction walk #2377 and from this branch writes byte-identical documents for all 409 .sysml/.kerml models under examples/ (pilot corpora included) and tests/testdata/.
  • New tests in internal/semantic/metamodel/structure_memo_test.go: a caller that edits a supertype or general-type list it was handed does not change the memoized one, and input, output and directedFeature keep their own selections when read in any order from the shared directions.
  • go build ./..., go vet ./..., gofmt -l . (empty), make lint, python3 scripts/changelog.py check and go test ./... pass on the merged tree (tests/hygiene re-run after the merge was committed, since its tracked-path check reads the index); go test -C tools ./referee/apijson passes.
  • API JSON differential: go run -C tools ./cmd/pilot-apijson-diff -check reproduces the committed baseline on this branch's head (935 files, the specification examples included). The workflow's own differential job is skipped on this pull request.

Checklist

  • make test and make lint pass locally (go test ./... without -race, and make lint)
  • Tests added or updated for the change
  • Documentation extended where it already covers the surface (see CONTRIBUTING.md) — none covers these internals
  • Changelog entry added as changes/unreleased/<slug>.<section>.md, not as an edit to CHANGELOG.md
  • baselines regenerated and make docs-counts run if a gate count moved (compliance rows need nothing: the census is counted at docs build) — no count moved
  • No internal work-item labels (waves, slices, F4, K5) in the body, docs, or changelog

Release Management opened this PR for Jason
Implemented in session Fix API JSON export regression from PR 1915
Review with Devin · Open in Devin Desktop


devin-ai-integration Bot and others added 2 commits November 18, 2026 20:52
…on walk

The effective-direction walk for port features recomputed Type::ownedFeature
and the owned supertypes of every type on the inheritance path, per feature.
Both are now derived once per element through the evaluator memo, and the
owned-feature test runs only for port usages, which alone read it.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…ons once per element

Type::input, Type::output and Type::directedFeature each walked every effective
feature's direction, and each walk re-derived the owned features and supertypes
of the owner and of every general type on the way. The three lists and the
directions are now memoized per element, so the API JSON export reads them once.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

…pertype memos of #2377

Merges perf/memoize-owned-features-direction-walk and drops this branch's own
memos of structureOwnedFeatures and structureOwnedSupertypes in favour of the
ones that branch carries; the general-type and feature-direction memos stay.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@devin-ai-integration devin-ai-integration Bot changed the title fix(metamodel): derive owned features, supertypes and feature directions once per element fix(metamodel): derive general types and feature directions once per element Nov 18, 2026
@HuiJun
HuiJun added this pull request to the merge queue Nov 19, 2026
Merged via the queue into develop with commit 17df973 Nov 19, 2026
32 checks passed
@HuiJun
HuiJun deleted the fix/api-json-inherited-member-allocs branch November 19, 2026 04:29
devin-ai-integration Bot added a commit that referenced this pull request Nov 19, 2026
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