Skip to content

Start-Job is now 6-10x slower, and does not preserve $env:PSModulePath #7402

Closed

Description

Steps to reproduce

$iter = 10
$env:PSModulePath = 'Custom PSModulePath'

Measure-Command {
    for( $i = 0; $i -lt $iter; $i++ )
    {
        $job = start-job -ScriptBlock { Write-Host $env:PSModulePath }
    }
}

Expected behavior

I should be able to kick off ten jobs in just a few seconds (maybe 2 or 3). When the results of the job come in, I should see Custom PSModulePath. This is the behavior in 5.1.

Actual behavior

It takes between 12 and 20 seconds. That's longer than a second per job! (and I'm not waiting for the job to finish; this is just the time for Start-Job to return) And then the output is the default module path.

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0-preview.4
PSEdition                      Core
GitCommitId                    6.1.0-preview.4-26-g668ce91ddb14d71177b4de4f94d99c3e429e4ff7
OS                             Microsoft Windows 10.0.17692
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. mklement0 commented on Jul 30, 2018

    @mklement0
    Contributor

    The performance is concerning, but note that the overriding of $env:PSModulePath is a more fundamental issue not specific to jobs - see #6850

  2. anmenaga commented on Jul 30, 2018

    @anmenaga

    I can Not repro the Perf problem.
    In my case time to start jobs in PSCore is in-line with PS Desktop / 5.1 on the same machine.

    TotalSeconds      : 1.8481092
    
    PS C:\WINDOWS\system32> $psversiontable
    
    Name                           Value
    ----                           -----
    PSVersion                      6.1.0-preview.4
    PSEdition                      Core
    GitCommitId                    6.1.0-preview.4
    OS                             Microsoft Windows 10.0.16299
    

    Dan Thompson (@jazzdelightsme) Your PSVersionTable looks like a manual PS build. Can you please try this repro on official packages on your hardware?

  3. MaximoTrinidad commented on Jul 30, 2018

    @MaximoTrinidad

    In my system both in Windows and Core took 1 sec to execute the script.

    pscorejob_2018-07-30_18-24-20

    Total milliseconds there are small difference:
    Windows: 1011.9632 vs Core: 1837.473

    But, you're correct about the PSModulePath as it didn't took the new value in PSCore. But, I won't ever mess with the original value in PSModulePath.

    I would rather append another path than completely change it.

    Receive-Job results:
    PSCore

    PS [55] > receive-job -id 1 -keep
    C:\Users\max_t\Documents\PowerShell\Modules;c:\temp;C:\Program Files\PowerShell\Modules;c:\program files\powershell\6-preview\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
    

    Windows PowerShell

    PS [78] > Receive-Job -id 1 -keep
    c:\temp
    

    PowerShell Core version:

    PS [66] > $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      6.1.0-preview.4
    PSEdition                      Core
    GitCommitId                    6.1.0-preview.4
    OS                             Microsoft Windows 10.0.17723
    Platform                       Win32NT
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0
    
  4. added
    Issue-Discussion
    on Jul 31, 2018
  5. BrucePay commented on Jul 31, 2018

    @BrucePay
    Collaborator

    The PSModulePath behaviour is currently by design. I have an RFC for how we might change it. Version Specific $ENV:PSModulePath Variables

  6. jazzdelightsme commented on Aug 1, 2018

    @jazzdelightsme
    ContributorAuthor

    Thanks Bruce Payette (@BrucePay). I've been wondering how people are handling the schism between the v5 module path and v6. What I did to try to make my life simpler was to use mklink to create directory junctions between the WindowsPowerShell and PowerShell directories (in the user docs and program files dirs) so I can have all my modules in both places. I am not using pwsh a ton yet, so I'm not sure how bad an idea that is. Is there a better way?

    Andrew (@anmenaga) and Maximo Trinidad (@MaximoTrinidad) : I tried the latest binary release (this one), and it was indeed faster than my privately-built bits. (I was building and testing using the 'Release' config). Now it is "only" 2x slower. On my system (an old Lenovo X1 Carbon laptop), win5.1 is 2-2.5 seconds, whereas pwsh is 5-6.

  7. SteveL-MSFT commented on Nov 4, 2019

    @SteveL-MSFT
    Member

    Dan Thompson (@jazzdelightsme) is this still an issue with PS7?

  8. jazzdelightsme commented on Nov 5, 2019

    @jazzdelightsme
    ContributorAuthor

    Steve Lee (@SteveL-MSFT) : yes, it is still a problem. In fact it's even worse from 6.2.2.0.

    On my current hardware (Lenovo X1 Yoga (Intel Core i7, 4 cores, 16 GB RAM)), 5.1 takes about 1.8 or 1.9 seconds to start ten jobs. 6.2.2.0 takes about 3.7 to 3.8 seconds. 7.0.0-preview.5 takes between 4.5 and 5.0 seconds to start ten jobs.

    (this is all using binary releases downloaded from github; not my own builds, of course)

    Actually, that was on battery power. On AC, the difference is a little less:

    version time
    5.1 1.4 - 1.5 seconds
    6.2.2.0 2.4 - 2.6 seconds
    7.0.0-preview.5 3.3 - 3.5 seconds

    But it's still clear that it's getting significantly slower.

  9. added
    WG-Engine-Performance
    on Nov 5, 2019
  10. daxian-dbw commented on Jan 21, 2020

    @daxian-dbw
    Member

    Start-Job starts up a new pwsh process, so this is just a symptom showing that there is a degradation in the startup time of pwsh.
    I don't find an issue tracking the degradation in the startup time of pwsh, but it's sort of a known issue internally.

    From 5.1 to 6.0/6.1/6.2, the worse startup time was mainly because of the use of crossgen vs. ngen. ngen, which is used by powershell.exe, generates more efficient code as it's targeting the particular machine the code runs on; while crossgen has to target a wide range of machines and thus generates code that's less efficient but more resilient.
    In 6.2 time frame, #8341 improved the startup time by about 25% comparing with 6.1.

    From 6.2 to 7.0, the startup time regressed mainly because .NET Core started to use the Ready-to-Run format for System.Private.CoreLib.dll and maybe a few other core libraries. They were ngen'ed previously.
    We probably should open an issue in GitHub tracking the startup time of pwsh, just to make it more transparent to the community.

  11. SteveL-MSFT commented on Jan 22, 2020

    @SteveL-MSFT
    Member

    The startup perf issue is #6443

  12. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  13. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  14. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  15. added
    Resolution-No Activity
    on Nov 16, 2023
  16. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-DiscussionResolution-No ActivityWG-Engine-Performance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions