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

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

Copy link
Contributor

@rjmholt rjmholt left a comment

Choose a reason for hiding this comment

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

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

@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
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.

3 participants