Skip to content

fix(symbols): memoize ShortNamed per index generation - #562

Merged
HuiJun merged 2 commits into
developfrom
fix/memoize-short-named
Sep 24, 2026
Merged

HuiJun merged 2 commits into
developfrom
fix/memoize-short-named

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What and why

The membership-import pruning that bounds importPrefixAvailable (#541) asks Index.ShortNamed whether any symbol under a given last-name segment is registered under a short name. That answer was recomputed on every call by walking every qualified name ending in the segment and every symbol under each, so a model with many membership imports — the Apollo 11 example has hundreds — spent ~25% of a whole-model -validate in ShortNamed, lastSeparator and map lookups (0.44 s → 0.55 s).

ShortNamed is now memoized per index generation, following the same pattern as lookupDirectChildren:

func (idx *Index) ShortNamed(name string) bool {
	idx.readSegment(name)                 // frame dependency recorded on hits too
	generation := idx.generation.get()
	// under directChildrenMu: reset caches if generation moved, return a hit
	v := idx.shortNamedScan(name)         // the previous body, unchanged
	// under directChildrenMu: store v only if the generation is still the same
}

The cache lives beside directChildrenCache and is reset with it in resetDirectChildrenCachesLocked, so any layer write (every set/del bumps the generation) invalidates it. The resolver-side ReadSegment dependency tracking is untouched.

How it was verified

Checklist

  • make test and make lint pass locally
  • Tests added or updated for the change
  • Documentation extended where it already covers the surface (see CONTRIBUTING.md)
  • 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 internal work-item labels (waves, slices, F4, K5) in the body, docs, or changelog

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

…t comparisons

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review September 24, 2026 08:20

@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 5d6e19a into develop Sep 24, 2026
15 checks passed
@HuiJun
HuiJun deleted the fix/memoize-short-named branch September 24, 2026 13:33
@devin-ai-integration devin-ai-integration Bot mentioned this pull request Sep 24, 2026
6 tasks
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