Reuse fuzzy matcher across completion candidates#4148
Open
kz357 wants to merge 1 commit into
Open
Conversation
add_builtins_autoimport_completions and add_local_variable_completions constructed a new SkimMatcherV2 for every candidate; SkimMatcherV2 carries thread-local caches meant to be reused across fuzzy_match calls so rebuilding it per candidate allocates those caches repeatedly and prevents DP-matrix cache from ever being reused. Matcher is taken out of the loop and reused, similar to state/lsp.rs. I think this will speed up the completion popup appearance, but I don't know if that's true or by how much as I didn't add a benchmark and neither typecheck_benchmark.py nor lsp_benchmark.py measures this. The change doesn't break anything in cargo test Related: issue facebook#2296
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
NathanTempest
approved these changes
Jul 16, 2026
NathanTempest
left a comment
Contributor
There was a problem hiding this comment.
Thanks @kz357 for the nice catch. Behavior is identical (same .smart_case(), same fuzzy_match calls) and it can't regress, so I'm comfortable landing it without a benchmark. If you do want to add a completions benchmark as a follow-up, that'd be a welcome addition to catch future regressions here. Other than that looks good for importing.
Contributor
|
@samwgoldman has imported this pull request. If you are a Meta employee, you can view this in D112421874. |
yangdanny97
approved these changes
Jul 16, 2026
yangdanny97
left a comment
Contributor
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
add_builtins_autoimport_completions and add_local_variable_completions constructed a new SkimMatcherV2 for every candidate; SkimMatcherV2 carries thread-local caches meant to be reused across fuzzy_match calls so rebuilding it per candidate allocates those caches repeatedly and prevents DP-matrix cache from ever being reused. Matcher is taken out of the loop and reused, similar to state/lsp.rs.
I think this will speed up the completion popup appearance, but I don't know if that's true or by how much as I didn't add a benchmark and neither typecheck_benchmark.py nor lsp_benchmark.py measures this. The change doesn't break anything in cargo test
Related: issue #2296
Test Plan
cargo test passes the same as before edits, cargo clippy and cargo fmt are clean
I don't think there's an existing benchmark that covers completions, but I'm happy to try to write one as a follow-up to this if it'd be useful