Skip to content

Fix performance related issues #692

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 8 commits into from
Jan 19, 2017
Merged

Fix performance related issues #692

merged 8 commits into from
Jan 19, 2017

Conversation

kapilmb
Copy link

@kapilmb kapilmb commented Jan 18, 2017

This fixes issues caused by the getcommandinfo method in Helper. The method still appears to be the bottleneck, however compared to the previous iteration, the fix improves performance by about an order of magnitude. Two representative samples are provided for reference. The measurements were taken on a run-of-the mill laptop and are given for illustrative purposes. If you try to repro, your actual observations might vary but with a very high chance the ratio of improvement will be similar to what is observed here.

Before

PowerShellGet

PS> measure-command {Invoke-ScriptAnalyzer C:\tmp\PowerShellGet\PowerShellGet\PSModule.psm1} | select TotalSeconds

TotalSeconds
------------
 124.3418109

PS> Get-ScriptAnalyzerRule  | % {$rule = $_; Measure-Command {Invoke-ScriptAnalyzer -includeRule $_.RuleName C:\tmp\PowerShellGet\PowerShellGet\PSModule.psm1} | select @{label='Rule'; expression={$rule.RuleName}},TotalSeconds} | sort TotalSeconds -Descending

Rule                                           TotalSeconds
----                                           ------------
PSUseCmdletCorrectly                            112.3700632
PSAvoidUsingPositionalParameters                 94.7514287
PSShouldProcess                                  15.2195746
PSProvideCommentHelp                              5.8494389
PSReservedCmdletChar                              1.0224324
PSUseApprovedVerbs                                0.5066656
PSUseShouldProcessForStateChangingFunctions       0.4255758
PSPlaceOpenBrace                                  0.4100349
PSAvoidGlobalVars                                 0.3787875
PSUsePSCredentialType                             0.3685841
PSAvoidUsingWMICmdlet                             0.3416407
PSDSCDscExamplesPresent                           0.3386432
PSDSCUseIdenticalParametersForDSC                 0.3244799
PSAvoidUsingComputerNameHardcoded                 0.3209524
PSUseSingularNouns                                0.2982308
PSUseDeclaredVarsMoreThanAssignments              0.2743223
PSAvoidUsingUserNameAndPassWordParams             0.2693301
PSAvoidUsingDeprecatedManifestFields              0.2607392
PSUseCompatibleCmdlets                            0.2570891
PSReservedParams                                  0.2430985
PSAvoidDefaultValueSwitchParameter                0.2359885
PSUseConsistentIndentation                        0.2114346
PSMisleadingBacktick                              0.2054826
PSAvoidUsingInvokeExpression                      0.2032705
PSPossibleIncorrectComparisonWithNull             0.1977471
PSAvoidDefaultValueForMandatoryParameter          0.1969852
PSUseOutputTypeCorrectly                          0.1951215
PSAvoidUsingWriteHost                             0.1929578
PSDSCStandardDSCFunctionsInResource               0.1917975
PSAvoidUsingConvertToSecureStringWithPlainText    0.1910929
PSAvoidInvokingEmptyMembers                       0.1907277
PSUseLiteralInitializerForHashtable               0.1886388
PSUseBOMForUnicodeEncodedFile                      0.187249
PSUseToExportFieldsInManifest                     0.1817377
PSDSCUseIdenticalMandatoryParametersForDSC        0.1813102
PSAvoidShouldContinueWithoutForce                 0.1788609
PSDSCDscTestsPresent                              0.1786472
PSAvoidUsingCmdletAliases                         0.1767872
PSAvoidGlobalAliases                              0.1762819
PSAvoidUsingEmptyCatchBlock                       0.1740668
PSAvoidUsingPlainTextForPassword                  0.1739352
PSAvoidGlobalFunctions                            0.1729614
PSDSCReturnCorrectTypesForDSCFunctions            0.1729324
PSUseUTF8EncodingForHelpFile                      0.1691073
PSMissingModuleManifestField                      0.1595594
PSAvoidNullOrEmptyHelpMessageAttribute            0.1591912
PSPlaceCloseBrace                                 0.1573854
PSDSCUseVerboseMessageInDSCResource               0.1536931

Plaster

PS> measure-command {Invoke-ScriptAnalyzer C:\tmp\Plaster -Recurse} | select TotalSeconds

TotalSeconds
------------
 187.0425816

PS> Get-ScriptAnalyzerRule  | % {$rule = $_; Measure-Command {Invoke-ScriptAnalyzer -includeRule $_.RuleName C:\tmp\Plaster -Recurse} | select @{label='Rule'; expression={$rule.RuleName}},TotalSeconds} | sort TotalSeconds -Descending

Rule                                           TotalSeconds
----                                           ------------
PSUseCmdletCorrectly                            157.0912772
PSAvoidUsingPositionalParameters                127.2269038
PSShouldProcess                                  58.6390874
PSProvideCommentHelp                              1.7463578
PSReservedCmdletChar                               1.724604
PSAvoidUsingCmdletAliases                         1.0810713
PSAvoidUsingDeprecatedManifestFields              0.7394356
PSUseDeclaredVarsMoreThanAssignments              0.6928283
PSMisleadingBacktick                              0.6419237
PSUseLiteralInitializerForHashtable               0.6034509
PSUseOutputTypeCorrectly                          0.5915063
PSMissingModuleManifestField                      0.5497644
PSAvoidInvokingEmptyMembers                       0.5207314
PSUseToExportFieldsInManifest                     0.5160303
PSUseConsistentIndentation                        0.5109632
PSUseCompatibleCmdlets                            0.5107688
PSUsePSCredentialType                             0.5088279
PSAvoidUsingWMICmdlet                             0.4838791
PSAvoidUsingWriteHost                              0.477048
PSUseSingularNouns                                0.4553756
PSAvoidUsingUserNameAndPassWordParams             0.4537896
PSAvoidUsingInvokeExpression                      0.4453121
PSAvoidDefaultValueSwitchParameter                 0.441522
PSAvoidGlobalAliases                              0.4361314
PSPossibleIncorrectComparisonWithNull             0.4351895
PSAvoidGlobalVars                                 0.4327928
PSAvoidGlobalFunctions                            0.4238595
PSAvoidShouldContinueWithoutForce                 0.4146334
PSAvoidDefaultValueForMandatoryParameter          0.4142368
PSAvoidNullOrEmptyHelpMessageAttribute            0.4136735
PSPlaceOpenBrace                                  0.4127836
PSReservedParams                                  0.3918665
PSAvoidUsingComputerNameHardcoded                 0.3880383
PSUseApprovedVerbs                                0.3864505
PSAvoidUsingConvertToSecureStringWithPlainText    0.3777394
PSAvoidUsingEmptyCatchBlock                       0.3775867
PSDSCDscTestsPresent                              0.3735128
PSAvoidUsingPlainTextForPassword                  0.3709337
PSPlaceCloseBrace                                 0.3641647
PSUseBOMForUnicodeEncodedFile                     0.3579814
PSUseShouldProcessForStateChangingFunctions       0.3561159
PSDSCDscExamplesPresent                           0.3258236
PSUseUTF8EncodingForHelpFile                      0.3215903
PSDSCUseIdenticalMandatoryParametersForDSC        0.3145811
PSDSCReturnCorrectTypesForDSCFunctions            0.3071837
PSDSCUseVerboseMessageInDSCResource               0.3055609
PSDSCUseIdenticalParametersForDSC                 0.2986616
PSDSCStandardDSCFunctionsInResource               0.2865243

After

PowerShellGet

PS> measure-command {Invoke-ScriptAnalyzer C:\tmp\PowerShellGet\PowerShellGet\PSModule.psm1} | select TotalSeconds

TotalSeconds
------------
  19.8818003

PS> Get-ScriptAnalyzerRule  | % {$rule = $_; Measure-Command {Invoke-ScriptAnalyzer -includeRule $_.RuleName C:\tmp\PowerShellGet\PowerShellGet\PSModule.psm1} | select @{label='Rule'; expression={$rule.RuleName}},TotalSeconds} | sort TotalSeconds -Descending

Rule                                           TotalSeconds
----                                           ------------
PSShouldProcess                                  10.9385864
PSUseCmdletCorrectly                              8.6218958
PSAvoidUsingPositionalParameters                  7.6779224
PSProvideCommentHelp                              4.7703389
PSAvoidUsingWriteHost                             0.5082368
PSUseBOMForUnicodeEncodedFile                     0.4635874
PSAvoidGlobalVars                                 0.4424783
PSPlaceOpenBrace                                  0.4385499
PSUseSingularNouns                                 0.423353
PSDSCUseIdenticalParametersForDSC                 0.4182576
PSAvoidUsingConvertToSecureStringWithPlainText    0.4144819
PSUsePSCredentialType                             0.4063117
PSDSCStandardDSCFunctionsInResource               0.3177802
PSUseShouldProcessForStateChangingFunctions       0.2945418
PSAvoidUsingEmptyCatchBlock                       0.2918377
PSUseUTF8EncodingForHelpFile                      0.2667042
PSUseCompatibleCmdlets                            0.2609338
PSUseDeclaredVarsMoreThanAssignments              0.2583656
PSAvoidDefaultValueSwitchParameter                0.2581881
PSReservedParams                                  0.2511306
PSAvoidUsingUserNameAndPassWordParams             0.2497873
PSUseApprovedVerbs                                0.2488775
PSAvoidUsingWMICmdlet                             0.2239661
PSReservedCmdletChar                              0.2233316
PSPlaceCloseBrace                                 0.2209228
PSDSCReturnCorrectTypesForDSCFunctions             0.214702
PSDSCUseVerboseMessageInDSCResource               0.2074139
PSMisleadingBacktick                              0.2068929
PSPossibleIncorrectComparisonWithNull             0.2053051
PSDSCUseIdenticalMandatoryParametersForDSC        0.2043874
PSMissingModuleManifestField                      0.2001246
PSUseConsistentIndentation                        0.1985688
PSUseOutputTypeCorrectly                          0.1968518
PSDSCDscExamplesPresent                           0.1961044
PSAvoidDefaultValueForMandatoryParameter          0.1953292
PSAvoidUsingComputerNameHardcoded                 0.1945275
PSAvoidInvokingEmptyMembers                       0.1930296
PSAvoidUsingDeprecatedManifestFields              0.1920039
PSUseToExportFieldsInManifest                     0.1902646
PSAvoidShouldContinueWithoutForce                 0.1882608
PSAvoidUsingPlainTextForPassword                  0.1856038
PSAvoidGlobalAliases                              0.1849325
PSUseLiteralInitializerForHashtable               0.1842467
PSDSCDscTestsPresent                               0.184001
PSAvoidGlobalFunctions                            0.1803672
PSAvoidNullOrEmptyHelpMessageAttribute            0.1786671
PSAvoidUsingCmdletAliases                          0.173489
PSAvoidUsingInvokeExpression                      0.1718976

Plaster

PS> measure-command {Invoke-ScriptAnalyzer C:\tmp\Plaster -Recurse} | select TotalSeconds

TotalSeconds
------------
  13.6759138

PS> Get-ScriptAnalyzerRule  | % {$rule = $_; Measure-Command {Invoke-ScriptAnalyzer -includeRule $_.RuleName C:\tmp\Plaster -Recurse} | select @{label='Rule'; expression={$rule.RuleName}},TotalSeconds} | sort TotalSeconds -Descending

Rule                                           TotalSeconds
----                                           ------------
PSShouldProcess                                   9.1071364
PSAvoidUsingPositionalParameters                  6.7994533
PSUseCmdletCorrectly                              6.6981984
PSAvoidUsingDeprecatedManifestFields              0.4847062
PSAvoidDefaultValueSwitchParameter                0.4578539
PSUseToExportFieldsInManifest                     0.4542527
PSAvoidInvokingEmptyMembers                       0.4478037
PSMissingModuleManifestField                      0.4165545
PSAvoidUsingCmdletAliases                         0.4124274
PSAvoidDefaultValueForMandatoryParameter          0.4103947
PSAvoidGlobalFunctions                            0.4076472
PSAvoidGlobalAliases                              0.4045126
PSDSCDscExamplesPresent                           0.3868918
PSUseDeclaredVarsMoreThanAssignments              0.3846424
PSUseCompatibleCmdlets                            0.3824738
PSAvoidNullOrEmptyHelpMessageAttribute            0.3812935
PSPlaceOpenBrace                                  0.3767499
PSUseLiteralInitializerForHashtable               0.3762657
PSAvoidUsingUserNameAndPassWordParams             0.3759784
PSMisleadingBacktick                               0.374335
PSAvoidUsingEmptyCatchBlock                       0.3740941
PSDSCStandardDSCFunctionsInResource               0.3718767
PSAvoidGlobalVars                                 0.3704634
PSReservedCmdletChar                              0.3694292
PSUseApprovedVerbs                                0.3677134
PSAvoidUsingWMICmdlet                             0.3635405
PSPossibleIncorrectComparisonWithNull             0.3631674
PSAvoidUsingPlainTextForPassword                  0.3493138
PSUseShouldProcessForStateChangingFunctions       0.3470172
PSUsePSCredentialType                             0.3469381
PSUseSingularNouns                                0.3429174
PSUseBOMForUnicodeEncodedFile                     0.3396204
PSUseConsistentIndentation                        0.3365203
PSAvoidShouldContinueWithoutForce                 0.3357101
PSReservedParams                                  0.3325756
PSAvoidUsingComputerNameHardcoded                 0.3291918
PSUseOutputTypeCorrectly                          0.3265861
PSAvoidUsingInvokeExpression                      0.3220684
PSUseUTF8EncodingForHelpFile                      0.3220057
PSAvoidUsingWriteHost                             0.3186399
PSDSCUseVerboseMessageInDSCResource               0.3126721
PSDSCDscTestsPresent                               0.312255
PSProvideCommentHelp                              0.3103762
PSPlaceCloseBrace                                 0.3039834
PSDSCUseIdenticalParametersForDSC                 0.3006822
PSDSCReturnCorrectTypesForDSCFunctions            0.3002361
PSAvoidUsingConvertToSecureStringWithPlainText    0.2972356
PSDSCUseIdenticalMandatoryParametersForDSC        0.2914272
```

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/powershell/psscriptanalyzer/692)
<!-- Reviewable:end -->

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.

Great work! I think users will be really happy with this speed improvement. I'm excited to see how much it affects the VS Code experience.

@kapilmb kapilmb force-pushed the kapilmb/FixPerformance branch from a2b9b42 to 8726c10 Compare January 19, 2017 04:17
@kapilmb
Copy link
Author

kapilmb commented Jan 19, 2017

Reverting some of the changes because of some hang issues.

@kapilmb kapilmb merged commit cc41f6d into development Jan 19, 2017
@kapilmb kapilmb deleted the kapilmb/FixPerformance branch January 19, 2017 04:29
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