Skip to content

Use iter.Seq for GetSpellingSuggestion#3190

Open
jakebailey wants to merge 9 commits intomainfrom
jabaile/faster-suggestion
Open

Use iter.Seq for GetSpellingSuggestion#3190
jakebailey wants to merge 9 commits intomainfrom
jabaile/faster-suggestion

Conversation

@jakebailey
Copy link
Member

Follow-up to #1640 and #3100 / #3100 (comment)

In bad code, the spelling checks can be very expensive. We can avoid sorting large symbol tables by instead just using iterators, keeping track of the best candidate. Only on tie breaks do we call a comparison function, which for symbols will be c.compareSymbols, the thing we would have sorted all symbols with anyway.

Also improves a few other cases where we can now use iterators instead of constructing big slices just to toss them away.

I'll note that in Strada, this was way less of a problem because we put a hard limit on how many spelling checks we would do. We got rid of that limit because it causes nondeterminism. So this becomes a bit more perf critical.

Copilot AI review requested due to automatic review settings March 21, 2026 19:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes spelling-suggestion generation across the compiler by switching candidate enumeration to iter.Seq-based iteration, avoiding large slice materializations and (in some cases) expensive full sorts while preserving deterministic results via explicit tie-breaking.

Changes:

  • Refactors core.GetSpellingSuggestion to accept iter.Seq candidates and a comparison function for deterministic tie-breaking.
  • Adds core.FilterSeq and updates multiple call sites to use iterator-based candidate production (maps.Keys, slices.Values, core.ConcatenateSeq).
  • Removes symbol-slice construction/sorting in several checker paths by iterating symbol tables directly and tie-breaking with c.compareSymbols.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/core/core.go Introduces FilterSeq; refactors spelling-suggestion API to use iter.Seq and explicit tie-breaking.
internal/checker/checker.go Updates symbol/type suggestion paths to use iterator-based candidates, avoiding full symbol-slice sorts.
internal/checker/jsx.go Switches JSX attribute suggestion to pass property candidates via slices.Values.
internal/parser/parser.go Uses iterator-based keyword candidates for missing-semicolon diagnostics.
internal/compiler/processingDiagnostic.go Uses iterator-based lib-name candidates for “cannot find lib” diagnostics.
internal/scanner/regexp.go Uses maps.Keys/ConcatenateSeq iterators for Unicode property name/value spelling suggestions.

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.

2 participants