Skip to content

refactor(export): build a document's identity facts through per-symbol helpers - #1802

Open
devin-ai-integration[bot] wants to merge 3 commits into
developfrom
refactor/export-identity-complexity
Open

devin-ai-integration[bot] wants to merge 3 commits into
developfrom
refactor/export-identity-complexity

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

What and why

SonarCloud's analysis of develop lists two open Go smells. This clears both with no change in behaviour; no suppression, no rule change, and no changelog fragment because nothing is user-visible.

Rule Location Sonar message Before → after
go:S3776 internal/translate/export/rdf_identity.go:137 Refactor this method to reduce its Cognitive Complexity from 34 to the 30 allowed. documentIdentity carried the whole per-symbol loop body (annotation decoding, scope keys, root lookup, the three index maps) in nested if/for/switch blocks → the loop calls facts.consumeAnnotated, facts.noteScope, identityRoot and facts.index, with newIdentityFacts building the struct; gocognit reads documentIdentity at 37 on develop, and after the split no function in the file is above 10 except the untouched subjectOf (24)
go:S1186 internal/exec/runtime/context.go:1917 Add a nested comment explaining why this function is empty or complete the implementation. release = func() {} for a reused execution → the closure says why it is empty: a reused execution is released by whoever first started it, so the caller that joins an execution in flight must release nothing — the no-op is the implementation, not a stub

documentIdentity still walks table.Symbols() in order, decodes the same annotations with the same error (returned at the same symbol), notes the same scope keys and fills the same three maps; the helpers are methods on the identityFacts it was already building, so no state moved and nothing is computed twice. Any edit under internal/translate/export moves the api-json writer's source digest, so the differential baseline is re-recorded on this tree.

The branch is merged with develop 5dfd33b8c (one merge commit). Develop's element_ids.go — satisfy-subject, positional-name, implied-conjugate, FeatureValue, expression-parameter, invocation-argument and reference-membership ids — is taken as is; the refactor touches rdf_identity.go only, and the identical scorecard below shows that every id develop writes is still written.

How it was verified

On the merged tree (develop 5dfd33b8c + this branch):

  • gofmt -l . empty, go build ./..., go vet ./... clean
  • go test -count=1 ./internal/translate/export/... ./tests/export/... ./internal/semantic/... — ok
  • go -C tools test -count=1 ./referee/apijson/... ./oracle/baseline/... — ok
  • OPENSYSML_REQUIRE_TRAINING_CORPUS=1 OPENSYSML_REQUIRE_PILOT_CORPORA=1 OPENSYSML_REQUIRE_SPEC_EXAMPLES=1 go test -count=1 ./tests/corpus -run '^TestCorpusRoundTrip$' — ok, no movement
  • go test -count=1 ./internal/exec/runtime/ -run 'TestExecutionConformance|TestExecutionTrace|TestRuntimeRobustness' — ok
  • go run -C tools ./cmd/pilot-apijson-diff -update on the merged tree, develop's baseline taken first — vs develop's baseline the diff is the writer sourceDigest line only (bbc0d624… → ea941750…); 932 files and every count identical (92426 matched, 1144182 present-equal / 27977 present-different / 1054265 ours-missing / 69343 pilot-missing / 26127 indeterminate)
  • benchstat of WriteAPIJSON (develop 5dfd33b8c vs branch, interleaved, n=6, plus n=10 on the then_after_members rows) posted as a comment: sec/op, B/op and allocs/op ~, output bytes identical

Checklist

  • make test and make lint pass locally (the gates above; the full race suite runs in CI)
  • Tests added or updated for the change — pure refactor, covered by the export, corpus and runtime suites
  • Documentation extended where it already covers the surface — none covers these internals
  • Changelog entry added — not user-visible, none added
  • baselines regenerated — docs/project/api-json-differential-baseline.json, writer digest only, identical counts
  • No internal work-item labels in the body, docs, or changelog

Link to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/33201010c187402c8fde446269d9a54c
Open in Devin Desktop: https://nasa-jpl-demo.devinenterprise.com/desktop/session/33201010c187402c8fde446269d9a54c?variant=devin
Requested by: @HuiJun

devin-ai-integration Bot and others added 2 commits October 31, 2026 05:40
Co-Authored-By: jason.han <hanhuijun@gmail.com>
…l helpers

documentIdentity's loop over the identity table now delegates to newIdentityFacts, consumeAnnotated, noteScope, identityRoot and index, so the same facts are gathered with the same errors in the same order. The runtime's reused-execution release closure says why it is empty. The api-json baseline re-records the writer digest only.

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

Copy link
Copy Markdown
Contributor Author

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 marked this pull request as ready for review October 31, 2026 05:42

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

Copy link
Copy Markdown
Contributor Author

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

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

benchstat for WriteAPIJSON, develop a37809a vs this branch, interleaved A/B on one machine (go test ./tests/export -run '^$' -bench WriteAPIJSON -benchmem, six rounds; one develop sample was lost to a grep of the first round's output, hence n=5+6). Every row is ~ for sec/op, B/op and allocs/op; the one allocs/op row with p=0.048 is 1.392M on both sides (the rounded means are equal, the difference is below the displayed precision). The output size is identical on every row.

                                           │   develop    │           branch            │
                                           │    sec/op    │    sec/op      vs base      │
WriteAPIJSON/ISQAtomicNuclear/standard-8     383.6m ± ∞ ¹   353.6m ±  60%  ~ (p=1.000 n=5+6)
WriteAPIJSON/ISQAtomicNuclear/compact-8      357.9m ± ∞ ¹   359.2m ±  24%  ~ (p=0.792 n=5+6)
WriteAPIJSON/SimpleVehicleModel/standard-8   540.7m ± ∞ ¹   614.0m ±  55%  ~ (p=0.247 n=5+6)
WriteAPIJSON/SimpleVehicleModel/compact-8    486.1m ± ∞ ¹   526.1m ± 110%  ~ (p=0.429 n=5+6)
WriteAPIJSON/then_after_members/standard-8   40.81m ± ∞ ¹   44.22m ±  34%  ~ (p=0.537 n=5+6)
WriteAPIJSON/then_after_members/compact-8    39.25m ± ∞ ¹   45.00m ±  67%  ~ (p=0.537 n=5+6)

                                           │   develop     │          branch           │
                                           │     B/op      │     B/op      vs base     │
WriteAPIJSON/ISQAtomicNuclear/standard-8     212.6Mi ± ∞ ¹   212.6Mi ± 0%  ~ (p=0.662 n=5+6)
WriteAPIJSON/ISQAtomicNuclear/compact-8      164.9Mi ± ∞ ¹   164.9Mi ± 0%  ~ (p=0.931 n=5+6)
WriteAPIJSON/SimpleVehicleModel/standard-8   349.6Mi ± ∞ ¹   349.7Mi ± 0%  ~ (p=0.931 n=5+6)
WriteAPIJSON/SimpleVehicleModel/compact-8    255.5Mi ± ∞ ¹   255.5Mi ± 0%  ~ (p=0.931 n=5+6)
WriteAPIJSON/then_after_members/standard-8   24.64Mi ± ∞ ¹   24.64Mi ± 0%  ~ (p=0.537 n=5+6)
WriteAPIJSON/then_after_members/compact-8    19.75Mi ± ∞ ¹   19.75Mi ± 0%  ~ (p=0.247 n=5+6)

                                           │   develop    │           branch              │
                                           │  allocs/op   │  allocs/op   vs base          │
WriteAPIJSON/ISQAtomicNuclear/standard-8     1.392M ± ∞ ¹   1.392M ± 0%  -0.00% (p=0.048 n=5+6)
WriteAPIJSON/ISQAtomicNuclear/compact-8      1.447M ± ∞ ¹   1.447M ± 0%       ~ (p=0.892 n=5+6)
WriteAPIJSON/SimpleVehicleModel/standard-8   1.723M ± ∞ ¹   1.723M ± 0%       ~ (p=0.121 n=5+6)
WriteAPIJSON/SimpleVehicleModel/compact-8    1.787M ± ∞ ¹   1.787M ± 0%       ~ (p=0.459 n=5+6)
WriteAPIJSON/then_after_members/standard-8   169.6k ± ∞ ¹   169.6k ± 0%       ~ (p=0.437 n=5+6)
WriteAPIJSON/then_after_members/compact-8    174.5k ± ∞ ¹   174.5k ± 0%       ~ (p=0.316 n=5+6)
¹ need >= 6 samples for confidence interval at level 0.95

The wide sec/op intervals come from the machine, not the change: the api-json baseline re-record and the export suites of another branch were running at the same time, and the memory and allocation columns — which that contention cannot move — are flat.

…entity-complexity

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

# Conflicts:
#	docs/project/api-json-differential-baseline.json
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

benchstat for WriteAPIJSON, develop 5dfd33b vs this branch at a521ae8 (the merge of that develop), interleaved A/B on one machine, own test binary per side, -test.bench '^BenchmarkWriteAPIJSON$' -test.benchmem, six rounds. sec/op, B/op and allocs/op are ~ on every row except then_after_members/compact, where B/op and allocs/op read -0.00% at p<0.05 (raw allocs/op 176504–176507 on develop vs 176503–176506 on the branch, overlapping); a dedicated ten-round run of the then_after_members rows below is ~ on every metric. Output bytes are identical on all rows (¹ all samples are equal).

                                           │ develop │   branch   │
                                           │             sec/op             │    sec/op     vs base              │
WriteAPIJSON/ISQAtomicNuclear/standard-8                       351.5m ±  4%   366.4m ± 15%       ~ (p=0.240 n=6)
WriteAPIJSON/ISQAtomicNuclear/compact-8                        341.8m ±  7%   350.6m ± 79%       ~ (p=0.589 n=6)
WriteAPIJSON/SimpleVehicleModel/standard-8                     541.2m ±  5%   545.1m ± 44%       ~ (p=0.699 n=6)
WriteAPIJSON/SimpleVehicleModel/compact-8                      514.3m ± 13%   517.9m ± 35%       ~ (p=0.818 n=6)
WriteAPIJSON/then_after_members/standard-8                     38.65m ±  7%   38.09m ±  5%       ~ (p=1.000 n=6)
WriteAPIJSON/then_after_members/compact-8                      38.50m ± 18%   39.20m ± 15%       ~ (p=0.937 n=6)
geomean                                                        191.8m         194.5m        +1.42%

                                           │ develop │   branch    │
                                           │            output-B            │   output-B    vs base                │
WriteAPIJSON/ISQAtomicNuclear/standard-8                       7.819Mi ± 0%   7.819Mi ± 0%       ~ (p=1.000 n=6) ¹
WriteAPIJSON/ISQAtomicNuclear/compact-8                        3.220Mi ± 0%   3.220Mi ± 0%       ~ (p=1.000 n=6) ¹
WriteAPIJSON/SimpleVehicleModel/standard-8                     13.80Mi ± 0%   13.80Mi ± 0%       ~ (p=1.000 n=6) ¹
WriteAPIJSON/SimpleVehicleModel/compact-8                      4.180Mi ± 0%   4.180Mi ± 0%       ~ (p=1.000 n=6) ¹
WriteAPIJSON/then_after_members/standard-8                     846.0Ki ± 0%   846.0Ki ± 0%       ~ (p=1.000 n=6) ¹
WriteAPIJSON/then_after_members/compact-8                      337.1Ki ± 0%   337.1Ki ± 0%       ~ (p=1.000 n=6) ¹
geomean                                                        2.709Mi        2.709Mi       +0.00%
¹ all samples are equal

                                           │ develop │   branch   │
                                           │              B/op              │     B/op      vs base              │
WriteAPIJSON/ISQAtomicNuclear/standard-8                       213.2Mi ± 0%   213.2Mi ± 0%       ~ (p=0.132 n=6)
WriteAPIJSON/ISQAtomicNuclear/compact-8                        165.4Mi ± 0%   165.4Mi ± 0%       ~ (p=0.394 n=6)
WriteAPIJSON/SimpleVehicleModel/standard-8                     350.5Mi ± 0%   350.5Mi ± 0%       ~ (p=0.818 n=6)
WriteAPIJSON/SimpleVehicleModel/compact-8                      256.3Mi ± 0%   256.2Mi ± 0%       ~ (p=0.818 n=6)
WriteAPIJSON/then_after_members/standard-8                     24.61Mi ± 0%   24.61Mi ± 0%       ~ (p=0.937 n=6)
WriteAPIJSON/then_after_members/compact-8                      19.73Mi ± 0%   19.73Mi ± 0%  -0.00% (p=0.009 n=6)
geomean                                                        107.4Mi        107.4Mi       -0.01%

                                           │ develop │  branch   │
                                           │           allocs/op            │  allocs/op   vs base              │
WriteAPIJSON/ISQAtomicNuclear/standard-8                        1.410M ± 0%   1.410M ± 0%       ~ (p=0.303 n=6)
WriteAPIJSON/ISQAtomicNuclear/compact-8                         1.465M ± 0%   1.465M ± 0%       ~ (p=0.913 n=6)
WriteAPIJSON/SimpleVehicleModel/standard-8                      1.744M ± 0%   1.744M ± 0%       ~ (p=0.937 n=6)
WriteAPIJSON/SimpleVehicleModel/compact-8                       1.808M ± 0%   1.808M ± 0%       ~ (p=0.615 n=6)
WriteAPIJSON/then_after_members/standard-8                      171.7k ± 0%   171.7k ± 0%       ~ (p=0.405 n=6)
WriteAPIJSON/then_after_members/compact-8                       176.5k ± 0%   176.5k ± 0%  -0.00% (p=0.045 n=6)
geomean                                                         763.0k        763.0k       -0.00%

Ten rounds, then_after_members only:

                                           │ develop │  branch  │
                                           │              sec/op              │   sec/op     vs base               │
WriteAPIJSON/then_after_members/standard-8                       37.76m ±  7%   37.61m ± 8%       ~ (p=0.971 n=10)
WriteAPIJSON/then_after_members/compact-8                        33.28m ± 17%   35.20m ± 6%       ~ (p=0.353 n=10)
geomean                                                          35.45m         36.38m       +2.63%

                                           │ develop │  branch   │
                                           │             output-B             │   output-B    vs base                 │
WriteAPIJSON/then_after_members/standard-8                       846.0Ki ± 0%   846.0Ki ± 0%       ~ (p=1.000 n=10) ¹
WriteAPIJSON/then_after_members/compact-8                        337.1Ki ± 0%   337.1Ki ± 0%       ~ (p=1.000 n=10) ¹
geomean                                                          534.0Ki        534.0Ki       +0.00%
¹ all samples are equal

                                           │ develop │  branch   │
                                           │               B/op               │     B/op      vs base               │
WriteAPIJSON/then_after_members/standard-8                       24.61Mi ± 0%   24.61Mi ± 0%       ~ (p=0.781 n=10)
WriteAPIJSON/then_after_members/compact-8                        19.73Mi ± 0%   19.73Mi ± 0%       ~ (p=0.645 n=10)
geomean                                                          22.03Mi        22.03Mi       +0.00%

                                           │ develop │  branch  │
                                           │            allocs/op             │  allocs/op   vs base               │
WriteAPIJSON/then_after_members/standard-8                        171.7k ± 0%   171.7k ± 0%       ~ (p=0.873 n=10)
WriteAPIJSON/then_after_members/compact-8                         176.5k ± 0%   176.5k ± 0%       ~ (p=0.596 n=10)
geomean                                                           174.1k        174.1k       +0.00%

This branch has not been deployed

No deployments
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