Fix help completion performance for large files #459
Merged
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.
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).
FunctionDefinitionAst.GetCommentHelp()
seems to be the bottleneck, which is called by thePSProvideCommentHelp
rule. If you disable this rule, analysis results are obtained almost instantaneously, except for the first time when a file is analyzed.PSProvideCommentHelp
rule to obtain the help snippet. When a user types the trigger characters, we the run the entire file against thePSProvideCommentHelp
rule, which as I already mentioned is the bottleneck thereby further degrading the performance.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 more50%
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.