Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Slow function when parameter is Mandatory its Type is specified #5417

Copy link
Copy link
@Atamido

Description

@Atamido
Issue body actions

Steps to reproduce

[Byte[]]$Value = [System.IO.File]::ReadAllBytes('C:\Some10MBfile')

#  ~1000ms for 10MB array
#  ~0.5ms for 1byte array
function MandType {
    Param (
        [parameter(Mandatory=$True)]
        [Byte[]]$Value
    )
}

#  ~0.3ms for 10MB array
function TypeOnly {
    Param (
        [parameter()]
        [Byte[]]$Value
    )
}

#  ~0.3 for 10MB array
function MandOnly {
    Param (
        [parameter(Mandatory=$True)]
        $Value
    )
}

(Measure-Command { MandType $Value}).TotalMilliseconds
(Measure-Command { MandType ([Byte[]]@(0))}).TotalMilliseconds
(Measure-Command { TypeOnly $Value}).TotalMilliseconds
(Measure-Command { MandOnly $Value}).TotalMilliseconds

Expected behavior

All versions of the above functions should behave identically and complete immediately, regardless of of parameter size as the functions perform no functions.

1.1
1.1
1.1
1.1

Actual behavior

When setting a parameter to Mandatory, specifying its Type, and passing a large array in, the function will pause for some amount of time before starting.

1000
1.1
1.1
1.1

Environment data

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-beta.9
PSEdition                      Core
GitCommitId                    v6.0.0-beta.9
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.16299.19
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.19
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.The issue is fixed.WG-Engine-Performancecore PowerShell engine, interpreter, and runtime performancecore PowerShell engine, interpreter, and runtime performance

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.