Skip to content

perf(check): keep one declaration per library package name until a second is met - #1746

Merged
HuiJun merged 2 commits into
developfrom
perf/duplicate-libraries-walk
Oct 30, 2026
Merged

HuiJun merged 2 commits into
developfrom
perf/duplicate-libraries-walk

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

What and why

Loading an empty model into a REPL allocates 2 155 times on the 0.12.0 candidate against 2 022 on 0.11.0's source built with the same toolchain (six rounds; exact). The +6.6 % is #1462's duplicate-library check: DuplicateLibraries walked every library document's root packages and appended each package symbol to a per-name slice, so the ~130 library packages, none of them duplicated, cost a slice allocation (and its growth) each on every load.

This PR keeps the check and its findings and changes only what it keeps for the common case: the first declaration of a name is held in a plain map until a second declaration of the same name is met, and only then does the name get a slice (seeded with both) and a place in the report order. The grouping of duplicates by the pair of trees, the used-declaration choice and the warning text are unchanged, as is the walk itself — a document count of root packages still has to be read, so the load does not return to 0.11.0's time.

A/B, six rounds (go test ./internal/frontend/repl -bench . -benchmem -count 1 × 6, benchstat; pre-#1462 / #1462 / candidate 1c6bb1972 / this branch; same host, "Intel(R) Xeon(R) Processor", 8 CPUs; bytes and allocations exact)

Row pre-#1462 #1462 candidate fix 0.11.0 source, go1.27.3
LoadModel/elements=0 allocs/op 2 021 2 151 (+6.43 %) 2 155 (+6.63 %) 2 038 (+0.84 %) 2 022
LoadModel/elements=0 B/op 227.9 Ki 246.7 Ki (+8.24 %) 246.8 Ki (+8.29 %) 238.1 Ki (+4.46 %) 228 Ki
LoadModel/elements=250, /1000, /4000 allocs/op and B/op unchanged vs the candidate (their +3.4 % allocs / +5.3 % bytes over pre-#1462 are #1478, fixed in #1744)
LoadModel/* live-B/op unchanged

Residual, stated in the fragment: 2 038 vs 2 022 allocations and 238 vs 228 Ki — the first map and the walk over the library roots are the check's cost. No sec/op claim: a full go test ./... gate ran on the host alongside rounds 1–3 and the timing columns carry ±100–300 % spread.

Memory acceptance

repl.test -test.bench '^BenchmarkLoadModel/elements=0$' -test.benchtime 200x, candidate and fix built the same way, three cold runs each, interleaved (/usr/bin/time, 8 CPUs):

run candidate peak RSS wall fix peak RSS wall
1 112.7 MiB 0.15 s 116.0 MiB 0.15 s
2 111.3 MiB 0.15 s 112.4 MiB 0.15 s
3 112.6 MiB 0.15 s 112.0 MiB 0.15 s

Hard cap: under ulimit -v 4000000 both pass (119 / 118 MiB peak RSS), and under ulimit -v 2000000 both pass too (117 / 113 MiB) — one earlier attempt of the fix under the 2 GB cap died in the Go runtime's arena reservation before loading anything, at 38 MB RSS, which the same binary did not repeat; that cap sits at the test binary's address-space reservation on either revision. Whole binary, sysml -validate over the 12 086-element generated model, three cold runs: 198 / 198 / 198 MiB candidate, 199 / 189 / 199 MiB fix, 0.24 s both; tests/stressmodel Load/512 1.27–1.36 GiB on both. Resident memory is not what this change recovers: it is 117 allocations and 9 KB per empty load, and the PR does not claim an RSS change.

How it was verified

  • The duplicate-library tests in internal/check/workspace (TestDuplicateLibrariesIsQuietWhenNothingIsDeclaredTwice, …ReportsAUserLibraryDeclaredTwice, …ReportsTwoCopiesOfAStandardLibraryFile, …GroupsATreeDeclaredTwice, …SurvivesAnInterfaceRecordReload) pass unchanged — the finding set is the same, only the bookkeeping for single declarations changed.
  • go test ./... below.

Gate

$ go build ./...        # ok
$ go vet ./...          # ok
$ gofmt -l .            # (empty)
$ go test -timeout 45m ./...
ok   124 packages, 0 FAIL, exit 0

(corpora present: training examples, pilot corpora, spec examples, pilot library XMI, PSSM suite, with their OPENSYSML_REQUIRE_* variables set.)

Checklist

  • go build ./..., go vet ./..., gofmt -l . (empty), go test ./... pass locally (above); make lint not run (the gate above is the repository's definition of done)
  • Tests added or updated for the change — the existing duplicate-library tests cover the finding set; no new behaviour
  • Documentation extended where it already covers the surface — none covers the check's bookkeeping
  • Changelog entry added as changes/unreleased/duplicate-libraries-walk.fixed.md
  • baselines regenerated and make docs-counts run if a gate count moved — no count moved
  • No internal work-item labels in the body, docs, or changelog

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

devin-ai-integration Bot and others added 2 commits October 30, 2026 03:16
…cond is met

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

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 30, 2026 09:45

@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

@HuiJun
HuiJun merged commit 411daa3 into develop Oct 30, 2026
30 of 51 checks passed
@HuiJun
HuiJun deleted the perf/duplicate-libraries-walk branch October 30, 2026 12:44
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