Skip to content

Reuse fuzzy matcher across completion candidates#4148

Open
kz357 wants to merge 1 commit into
facebook:mainfrom
kz357:perf/issue-2296-hoist-fuzzy-matcher
Open

Reuse fuzzy matcher across completion candidates#4148
kz357 wants to merge 1 commit into
facebook:mainfrom
kz357:perf/issue-2296-hoist-fuzzy-matcher

Conversation

@kz357

@kz357 kz357 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

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

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
@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@NathanTempest NathanTempest left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@meta-codesync

meta-codesync Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@samwgoldman has imported this pull request. If you are a Meta employee, you can view this in D112421874.

@yangdanny97 yangdanny97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants