-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
area-conceptualArea - Conceptual articlesArea - Conceptual articles
Description
This was fixed quite a while ago.
See src\System.Management.Automation\engine\runtime\Operations\MiscOps.cs:468-475
var cmdletInfo = commandProcessor?.CommandInfo as CmdletInfo;
if (cmdletInfo?.ImplementingType == typeof(OutNullCommand))
{
var commandsCount = pipelineProcessor.Commands.Count;
if (commandsCount == 1)
{
// Out-Null is the only command, bail without running anything
return;
}
// Out-Null is the last command, rewrite command before Out-Null to a null pipe, but
// only if it didn't redirect anything, e.g. `Get-Stuff > o.txt | Out-Null`
var nextToLastCommand = pipelineProcessor.Commands[commandsCount - 2];
if (!nextToLastCommand.CommandRuntime.OutputPipe.IsRedirected)
{
pipelineProcessor.Commands.RemoveAt(commandsCount - 1);
commandProcessor = nextToLastCommand;
nextToLastCommand.CommandRuntime.OutputPipe = new Pipe { NullPipe = true };
}
}A null pipe is created if piped to out-null. It is roughly 10% slower than assigning to $null, but in most cases not even noticeable.
PS > measure-command { 1..1000000 | foreach{$_} | out-null} | ftDays Hours Minutes Seconds Milliseconds
---- ----- ------- ------- ------------
0 0 0 3 701
PS > measure-command { $null = 1..1000000 | foreach{$_}} | ftDays Hours Minutes Seconds Milliseconds
---- ----- ------- ------- ------------
0 0 0 3 51
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: e911b722-86ce-7553-e9ab-33927e126b46
- Version Independent ID: 9818d91b-8c5f-337a-f5e1-7a40abd5fd1a
- Content: PowerShell scripting performance considerations - PowerShell
- Content Source: reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md
- Product: powershell
- Technology: powershell-conceptual
- GitHub Login: @sdwheeler
- Microsoft Alias: sewhee
Metadata
Metadata
Assignees
Labels
area-conceptualArea - Conceptual articlesArea - Conceptual articles