Powershell: Progress Reporting makes Invoke-RestMethod 70x slower

Created on 12 Sep 2016  路  4Comments  路  Source: PowerShell/PowerShell

Steps to reproduce

#Run with progress reporting disabled
$ProgressPreference = 'SilentlyContinue'
Measure-Command {
    Invoke-RestMethod https://archive.apache.org/dist/lucene/solr/6.2.0/solr-6.2.0.zip -OutFile 2.zip
} | select TotalSeconds

#Now run with the default Progress Preference value
$ProgressPreference = 'Continue'
Measure-Command {
    Invoke-RestMethod https://archive.apache.org/dist/lucene/solr/6.2.0/solr-6.2.0.zip -OutFile 1.zip
} | select TotalSeconds

Expected behavior

I'd expect progress reporting to have a small overhead, but not a significant one

Actual behavior

$ProgressPreference = 'Continue' is about 70 times slower than 'SilentlyContinue'. (On PS 5.1 in the latest Win 10 preview it is about 120x slower)

------------
    8.471039
  589.319871

Environment data

> $PSVersionTable
Name                           Value
----                           -----
SerializationVersion           1.1.0.1
PSEdition                      Core
PSVersion                      6.0.0-alpha
WSManStackVersion              3.0
BuildVersion                   3.0.0.0
GitCommitId                    v6.0.0-alpha.9
PSRemotingProtocolVersion      2.3
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
CLRVersion
Resolution-Duplicate WG-Engine-Performance WG-Interactive-Console

Most helpful comment

It is a proper issue. But the real culprit here is probably the implementation of console host WriteProgress(). It can be improved for all cmdlets, including Invoke-RestMethod.

https://connect.microsoft.com/PowerShell/feedback/details/337323

All 4 comments

It is a proper issue. But the real culprit here is probably the implementation of console host WriteProgress(). It can be improved for all cmdlets, including Invoke-RestMethod.

https://connect.microsoft.com/PowerShell/feedback/details/337323

@nightroman I get the point of that connect item, but it seems to be putting the onus on powershell to ignore too many calls to WriteProgress instead of - imo rightfully - blaming the caller for making too many calls :) That said, the base performance could likely be improved, absolutely.

I'm surprised that it is _faster_ in PS 6 than in PS 5.1. Wow.

Was this page helpful?
0 / 5 - 0 ratings