perf(inline-suggest): score completion candidates once instead of three times#1741
perf(inline-suggest): score completion candidates once instead of three times#1741desperadoxhy wants to merge 1 commit into
Conversation
|
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. 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. |
|
I have read the CLA Document and I hereby sign the CLA. |
There was a problem hiding this comment.
💡 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 |
There was a problem hiding this comment.
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 👍 / 👎.
问题
SQLCompletionProvider 的 filterByPrefix、populateMatchRanges、rankResults 对每个候选各算一遍 fuzzyMatchScore,rankResults 比较器里又算,总 O(n log n · m)。SELECT 子句 200+ 列候选时每键几百次模糊匹配。
方案
合并 fuzzyMatchScore 与 fuzzyMatchWithIndices 为一次 resolveFuzzyMatch,filterByPrefix 一次完成过滤 + matchedRanges + penalty 折叠进 sortPriority(加法可交换,排序结果不变)。三次扫描降到一次。公开签名(filterByPrefix / filterAndRank)不变。
验证