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

Improve performance of UseConsistentIndentation even more > another 10% speedup for formatter #1461

Conversation

@bergmeister
Copy link
Collaborator

bergmeister commented Apr 24, 2020

PR Summary

This now reduced the total CPU time of this rule to only from 12% to 2% on a run of a warm run Invoke-Formatter (compared to current master with the 3 recent speed improvements). Improvements will be smaller for smaller scripts as this was tested against PowerShell's build.psm1 3000+ line module (same as with previous PRs), therefore it rather ensures performance scales much better.
Basically, because the rule goes over every token, any looping, inside it, even when it is only performed for each line as in this case, it has a measurable impact (both in the profiler but also actual timings). Therfore making sure we iterate over fewer items in the pipelineAsts list, by having a minimum index, which increases with each line and breaking the loop early if the line number is bigger than the current line. This is possible because the queried function PositionIsEqual only returns pipeline asts on the same line.

PR Checklist

…peedup for formatter
Copy link
Member

rjmholt left a comment

Really awesome! Honestly I think removing LINQ use generally from PSSA could provide performance boosts across the board

Co-Authored-By: Robert Holt <rjmholt@gmail.com>
@bergmeister
Copy link
Collaborator Author

bergmeister commented Apr 24, 2020

Honestly I think removing LINQ use generally from PSSA could provide performance boosts across the board

Now, Linq consumers 18.5% of the CPU (but this include everything including SMA, therefore it is hard to say how much of that stems from PSSA only), so there is some potential but it's not as big as one would think.

image

@bergmeister bergmeister changed the title Improve performance of UseConsistentIndentation -more > another 10% speedup for formatter Improve performance of UseConsistentIndentation even more > another 10% speedup for formatter Apr 24, 2020
@bergmeister bergmeister merged commit eefa971 into PowerShell:master Apr 24, 2020
12 checks passed
12 checks passed
PSScriptAnalyzer-CI Build #20200424.4 succeeded
Details
PSScriptAnalyzer-CI (Build Full_Build) Build Full_Build succeeded
Details
PSScriptAnalyzer-CI (Test Ubuntu_16_04) Test Ubuntu_16_04 succeeded
Details
PSScriptAnalyzer-CI (Test Ubuntu_18_04) Test Ubuntu_18_04 succeeded
Details
PSScriptAnalyzer-CI (Test Windows_Server2016_PowerShell_5_1) Test Windows_Server2016_PowerShell_5_1 succeeded
Details
PSScriptAnalyzer-CI (Test Windows_Server2016_PowerShell_Core) Test Windows_Server2016_PowerShell_Core succeeded
Details
PSScriptAnalyzer-CI (Test Windows_Server2019_PowerShell_5_1) Test Windows_Server2019_PowerShell_5_1 succeeded
Details
PSScriptAnalyzer-CI (Test Windows_Server2019_PowerShell_Core) Test Windows_Server2019_PowerShell_Core succeeded
Details
PSScriptAnalyzer-CI (Test macOS_10_14_Mojave) Test macOS_10_14_Mojave succeeded
Details
PSScriptAnalyzer-CI (Test macOS_10_15_Catalina) Test macOS_10_15_Catalina succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
license/cla All CLA requirements met.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.