Skip to content

perf(inline-suggest): score completion candidates once instead of three times#1741

Open
desperadoxhy wants to merge 1 commit into
TableProApp:mainfrom
desperadoxhy:perf/completion-fuzzy-dedupe
Open

perf(inline-suggest): score completion candidates once instead of three times#1741
desperadoxhy wants to merge 1 commit into
TableProApp:mainfrom
desperadoxhy:perf/completion-fuzzy-dedupe

Conversation

@desperadoxhy

Copy link
Copy Markdown
Contributor

问题

SQLCompletionProvider 的 filterByPrefix、populateMatchRanges、rankResults 对每个候选各算一遍 fuzzyMatchScore,rankResults 比较器里又算,总 O(n log n · m)。SELECT 子句 200+ 列候选时每键几百次模糊匹配。

方案

合并 fuzzyMatchScore 与 fuzzyMatchWithIndices 为一次 resolveFuzzyMatch,filterByPrefix 一次完成过滤 + matchedRanges + penalty 折叠进 sortPriority(加法可交换,排序结果不变)。三次扫描降到一次。公开签名(filterByPrefix / filterAndRank)不变。

验证

  • BUILD SUCCEEDED
  • 新增 orderMatchesReferenceRank:对 8 个前缀 × 13 个候选穷举比对,断言去重后排序与原始三步排序完全一致
  • 既有 27 个补全测试全过

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Before we can merge this PR, you need to sign our Contributor License Agreement.

To sign, please comment below with:

I have read the CLA Document and I hereby sign the CLA.


I have read the CLA Document and I hereby sign the CLA.


xuhengyu seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@desperadoxhy

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5dd31ecaa0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

item.matchedRanges = [containsRange]
} else if let resolution = resolveFuzzyMatch(pattern: lowerPrefix, target: item.filterText) {
item.matchedRanges = indicesToRanges(resolution.indices)
item.sortPriority += resolution.penalty

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid storing fuzzy penalties in sortPriority

When completions are first opened while the current token is already a fuzzy-only match (for example sl matching SPLIT_PART), this mutates the returned SQLCompletionItems. SQLCompletionAdapter stores those items in the session and later calls filterAndRank on context.items as the cursor moves, so a longer fuzzy prefix adds another penalty on top of the old one instead of ranking from the base priority. This over-demotes fuzzy suggestions for the rest of that autocomplete session; keep the folded penalty out of the item or reset it before returning/caching.

Useful? React with 👍 / 👎.

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