Skip to content

perf(runtime): read a declaration's member from its scope's index - #1369

Merged
HuiJun merged 1 commit into
developfrom
perf/member-symbol-by-decl
Oct 22, 2026
Merged

HuiJun merged 1 commit into
developfrom
perf/member-symbol-by-decl

Conversation

@devin-ai-integration

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

Copy link
Copy Markdown
Contributor

What and why

runtime.memberSymbol(scope, node) returned the symbol a scope registered for a declaration by collecting every member of the scope (Scope.AllMembers, which allocates the slice) and scanning it. Scope.MemberDeclaring already answers the same question — the first registration of the declaration, as the scan found — from the scope's lazily built declaration index without allocating, so memberSymbol now calls it. Twelve runtime call sites share the helper.

The cost became visible when a nested requirement's subject was bound to its enclosing part (#1312): roleRedefiningDefault asks memberSymbol for every member of every instantiated type, and the 0.11.0 performance measurement of develop against v0.10.1 has tests/perf Instantiate at 2.51 M → 6.34 M allocations, of which 4.94 M → 6.34 M is that merge; the profile puts 1.81 M of it in memberSymbol → Scope.AllMembers.

Six interleaved rounds on a quiet machine, develop (5db0f74) | #1368 | this branch | both (benchstat, allocations exact, p = 0.002 on every moved row):

benchmark allocs/op B/op time
tests/perf Instantiate 6.338 M | 4.224 M | 5.012 M | 2.219 M 425 | 338 | 389 | 207 MiB 1.52 | 1.03 | 1.44 | 0.73 s
tests/perf BatchSatisfy 8.301 M | 5.672 M | 6.965 M | 4.336 M 602 | 492 | 565 | 456 MiB 2.18 | 1.53 | 2.02 | 1.42 s
tests/perf FeaturesOf 6.450 M | 3.683 M | 5.030 M | 2.263 M 413 | 298 | 376 | 261 MiB 1.29 | 0.70 | 1.22 | 0.67 s
tests/stressmodel Satisfy/32 42.03 k | 42.03 k | 40.04 k | 40.04 k — ~
tests/stressmodel FleetSatisfy/32 11.50 k | 11.50 k | 11.00 k | 11.00 k — ~
tests/stressmodel FleetInstantiate/32 15.45 k | 15.45 k | 15.29 k | 15.29 k — ~

v0.10.1: Instantiate 2.509 M, BatchSatisfy 4.301 M, FeaturesOf 4.130 M, Satisfy/32 33.4 k — with both fixes the tests/perf rows are at or below the previous release; the stress rows' remainder (+20 %) is #1276/#1319's wider type set, carried in the record as the earlier candidate measured it.

How it was verified

  • TestMemberSymbolReadsTheScopeWithoutCollectingIt (new): the lookup answers the member declared for each of a scope's declarations and allocates nothing; on develop it allocates 3 per lookup.
  • go build ./..., go vet ./..., gofmt -l . clean; go test of internal/exec/..., internal/frontend/repl, internal/frontend/grpc, tests/model green (the two internal/exec/solve corpus tests that need the downloaded training corpus fail identically on bare develop in this checkout).

Checklist

  • make test and make lint pass locally (the packages above; full suite in CI)
  • Tests added or updated for the change
  • Documentation extended where it already covers the surface (the 0.11.0 performance record names this fix in its correction)
  • Changelog entry added as changes/unreleased/member-symbol-by-decl.fixed.md
  • baselines regenerated and make docs-counts run if a gate count moved (none moved)
  • No internal work-item labels in the body, docs, or changelog

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


Devin Review

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 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
devin-ai-integration Bot marked this pull request as ready for review October 21, 2026 22:37
@HuiJun
HuiJun merged commit d777244 into develop Oct 22, 2026
51 checks passed
@HuiJun
HuiJun deleted the perf/member-symbol-by-decl branch October 22, 2026 00:42
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