-
Notifications
You must be signed in to change notification settings - Fork 394
Improve compatibility profile performance and make profiles a part of central configuration #1484
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
Comments
We are using PSScriptAnalyzer in our GitLab street and currently experiencing the issue described here: After opening a new PowerShell session, the initial Measure-Command {
Invoke-ScriptAnalyzer -Path .\Test.ps1 -Settings @{
Rules = @{
PSUseCompatibleCommands = @{
Enable = $true
TargetProfiles = @(
'win-8_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework',
'win-8_x64_10.0.17763.0_7.0.0_x64_3.1.2_core'
)
}
PSUseCompatibleSyntax = @{
Enable = $true
TargetVersions = @(
'5.1',
'7.0'
)
}
}
}
} Any successive invocation takes less than .5 seconds. PSScriptAnalyzer version:
|
The performance issues here occur because the profiles are stored in very large JSON files, which are parsed using reflection with Newtonsoft code. There's probably also some large object heap involvement too. Those files have to be loaded up on cold start, and even parsing them lazily doesn't avoid the huge memory consumption that probably drives much of the performance issues. A workaround might be to amortise cold starts by turning this into a service shared across CI workers. An interim solution would be to change out the JSON parsing code to use pre-generated stream parsing, probably using Microsoft's JSON parsing library. The best solution would be to convert the compatibility profiles into a Sqlite DB and ship PSSA with bindings for that |
Thank you for the feedback. Unfortunately, this is quiet hard for us to implement. From the reply from @bergmeister
Does that mean that I actually should create a separate issue for this? |
Yeah PSSA as a service is just something I suggest if no changes will be made to the compatibility rules. I suspect it would be easier to implement than rewriting the compatibility rules yourself. I no longer work at Microsoft so I don't know what the plans or processes are beyond what you know already, but I don't imagine a separate issue would help here |
I'm also observing a performance issue which is related to the cold start. In my case, every time I run the tests, they start in a fresh PS Session, so I'm always hitting the fresh start penalty. Usually, the delay out of initialization is longer than all the PSSA related tests. It would be great, if there was a way to trigger the cold start process in the very beginning (i.e. before all the other tests and prep tasks) so that it would run asynchronously (i.e. in a separate thread or runspace) and by the time my script gets to running PSSA tests, those large JSONs should already be loaded, i.e.:
|
Compatibility profiles are currently very slow to start up and use opaque and duplicated configurations across rules.
Instead:
The text was updated successfully, but these errors were encountered: