Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issues with CompletionsProcessor #1240

Closed
markwpearce opened this issue Jun 26, 2024 · 1 comment
Closed

Performance issues with CompletionsProcessor #1240

markwpearce opened this issue Jun 26, 2024 · 1 comment
Milestone

Comments

@markwpearce
Copy link
Collaborator

To get completions in v1, the CompletionsProcessor currently does a scope linking and symbol table lookup for EVERY scope, then checks to see if any resultant completions are valid for every scope.

For a file in many scopes, this can take a bit of time (sometimes greater than 500 ms).

There are probably ways to speed this up, perhaps by creating a temporary scope that is the intersection of all scopes for a file, then linking and doing symbol table lookups once for this temporary scope.

@markwpearce markwpearce added this to the v1.1.0 milestone Jun 26, 2024
@TwitchBronBron
Copy link
Member

In a recent PR to master (and the lsp rewrite branch), we switched to building completions from a subset of all scopes. Not sure why it hasn't made its way into v1, but we should ensure this functionality makes its way into v1.

//find the scopes for this file (sort by name so these results are always consistent)
let scopesForFile = this.event.program.getScopesForFile(this.event.file).sort(firstBy(x => x.name));
//if there are no scopes, include the global scope so we at least get the built-in functions
scopesForFile = scopesForFile.length > 0 ? scopesForFile : [this.event.program.globalScope];
// Only process the first few scopes. This might result in missing completions,
// but it's better than wasting TONS of cycles building essentially the same completions over and over
const scopesToProcess = scopesForFile.slice(0, 3);
// always include the source scope if applicable to this file
let sourceScope = scopesForFile.find(x => x.name === 'source');
if (sourceScope && !scopesToProcess.includes(sourceScope)) {
//replace the first scope with the source scope so we always process exactly 3 scopes
scopesToProcess[0] = sourceScope;
}

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

No branches or pull requests

2 participants