Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module loading performance is slow #38

Open
stephanjohnson opened this issue Dec 12, 2018 · 2 comments
Open

Module loading performance is slow #38

stephanjohnson opened this issue Dec 12, 2018 · 2 comments

Comments

@stephanjohnson
Copy link

When I enable PowerLine as part of my profile.ps1 PowerShell reports the following message:

Loading personal and system profiles took 1608ms

Loading times vary between 1600 and 1800ms.

Is there any way to optimize the loading time?

here is my profile.ps1 file:

#requires -module @{ModuleName='PowerLine';ModuleVersion='3.0.3'}, @{ModuleName='PSGit'; ModuleVersion='2.0.4'}

$global:prompt = @(
    { "&Gear;" * $NestedPromptLevel }
    { if($pushd = (Get-Location -Stack).count) { "$([char]187)" + $pushd } }
    { $pwd.Drive.Name }
    { Split-Path $pwd -leaf }
    { Get-GitStatusPowerline }
)

Set-PowerLinePrompt -SetCurrentDirectory -PowerLineFont -Title {
    -join @(if (Test-Elevation) { "Administrator: " }
        if ($IsCoreCLR) { "pwsh - " } else { "Windows PowerShell - "}
        Convert-Path $pwd)
} -Colors "DarkBlue", "White", "Cyan", "White", "DarkBlue", "DarkCyan"

Regards,

Stephan

@JustinGrote
Copy link

I was doing some profiling on this and a couple of the major ones are taking the dependency on the Configuration Module and the Add-Type for EmptyStringAsNullAttribute.

The add-type adds nearly a second to the load time for me, and Configuration module another 500ms. I hand-edited the code to remove these two dependencies and load time dropped down to 300ms cold start which is much more reasonable for something that is going to run "first time" on every load and greatly impacts the users perception of their powershell performance.

@Jaykul
Copy link
Owner

Jaykul commented Oct 26, 2019

I'm not sure I can safely take off the EmptyStringAsNull on the color parameters, but I could easily put that attribute type into the PANSIES assembly and remove the Add-Type call. That would be an easy win, so I will definitely do that.

The configuration module I'm not so sure about. Without it, you need to reconfigure your prompt in your profile on each load (and any time you wanted to change the configuration, you have to edit your profile). Part of the performance problem may be implicit module loading. For best performance, in your profile you should have a Import-Module statement that lists all the modules you need in a single line, in dependency order. E.g.:

Import-Module Configuration, PANSIES, PowerLine

If I wanted to make Configuration optional I would need to rely on documentation, and as you can see from the other issues, we already have problems with people not understanding the insufficient docs.

That is, I could make Set-PowerLinePrompt only call Import-Configuration if the Configuration module is already imported, and then hack the module packaging so that Install-Module still installs Configuration, but Import-Module doesn't implicitly import it... but then people who wanted convenience would have to manually specify the Configuration module in their profile...

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

No branches or pull requests

3 participants