Powershell: Performance Issue with foreach - paralllel

Created on 7 May 2020  路  3Comments  路  Source: PowerShell/PowerShell

Hi guys

the attached test runs on my machine (Powershell V7) astonishingly 30 seconds.

Can this be true? It has only 10k records and I dont get the performance issue?

Can you please clarify the issue?

Thanks,

Alex

tmp.txt

Steps to reproduce


    $myTest = Get-Content 'tmp.txt' | ConvertFrom-Json | Select-Object 'InputObject'
Measure-Command {
    $myTest | ForEach-Object -parallel {}
}

Expected behavior

This shouldnt take 30 seconds imho

Environment data

$PSVersionTable.PSVersion


Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
7      0      0




Issue-Question Resolution-Answered

All 3 comments

@Schwanowski In 7.0 new runspaces is created for every input object. It is really slow.
You can try latest 7.1 preview nightly build where some optimizations was added.

Additionally, if the overall processing required for each runspace is small, you will have better results in both versions if you batch the inputs for processing.

Thanks, we can leave this for the moment. I will try this again when 7.1 is out

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alx9r picture alx9r  路  3Comments

manofspirit picture manofspirit  路  3Comments

rudolfvesely picture rudolfvesely  路  3Comments

MaximoTrinidad picture MaximoTrinidad  路  3Comments

JohnLBevan picture JohnLBevan  路  3Comments