Skip to content

Fix help completion performance for large files #459

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

Merged
merged 3 commits into from
May 23, 2017

Conversation

kapilmb
Copy link

@kapilmb kapilmb commented May 20, 2017

This PR partly fixes the performance issue mentioned in PowerShell/vscode-powershell#771. I have identified the following 3 reasons why performance is poor for help completion in large script (having 100+ functions).

  1. Whenever a user makes a change to the file, the server starts analyzing the file for any diagnostic markers. For a large script, FunctionDefinitionAst.GetCommentHelp() seems to be the bottleneck, which is called by the PSProvideCommentHelp rule. If you disable this rule, analysis results are obtained almost instantaneously, except for the first time when a file is analyzed.
  2. Our implementation for help completion was inefficient, in the sense, that it relies on running PSProvideCommentHelp rule to obtain the help snippet. When a user types the trigger characters, we the run the entire file against the PSProvideCommentHelp rule, which as I already mentioned is the bottleneck thereby further degrading the performance.
  3. Both, diagnostic marker request and help completion request call PSSA on the same runspace. As such the requests are honored sequentially. So, if the user types the trigger characters and an analysis request is honored before help completion, then the help completion request is kept pending till the file markers are obtained, which further slows down the snippet completion.

To tackle issue 1, we need to identify the performance issues with FunctionDefinitionAst.GetCommentHelp() implementation in PowerShell. We tried tackling issue 3 previously, but it lead to hard-to-solve crash issues. So, this PR addresses only issue 2, as we only need to add an analysis api to get some performance improvement. I did some unscientific experiments on this file, which has more than 15k lines, and found out that addressing 2 consistently shaves off more 50% of the delay in completing the comment help snippet. I also observed that sometimes the completion is even instantaneous, which happens because the completion request gets honored before the marker request.

I would like to note that if the user disables the PSProvideCommentHelp rule, either through the rule picker or a PSSA settings file, comment help completion will be instantaneous even for large files.

Copy link
Contributor

@daviwil daviwil left a comment

Choose a reason for hiding this comment

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

Looks good man!

@kapilmb kapilmb merged commit 7e010aa into PowerShell:master May 23, 2017
@kapilmb
Copy link
Author

kapilmb commented May 23, 2017

Thanks @daviwil!

@kapilmb kapilmb deleted the fix-help-completion branch May 23, 2017 22:22
@daviwil daviwil modified the milestone: 1.2.0 May 31, 2017
TylerLeonhardt pushed a commit to TylerLeonhardt/PowerShellEditorServices that referenced this pull request Feb 26, 2019
…tifacts

Upload extension VSIX to AppVeyor on successful build
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.

3 participants