JanDeDobbeleer / oh-my-posh2

A prompt theming engine for Powershell
MIT License
5.18k stars 281 forks source link

Reduce startup time of Powershell profile on oh-my-posh #251

Closed cardin closed 4 years ago

cardin commented 4 years ago

Problem Installing oh-my-posh and post-git has increased the average Powershell startup time from negligible to 500-2000 ms. Powershell even mentions it: "Loading personal and system profiles took 1084ms."

Tried on an empty Powershell 7 profile and an empty Powershell 5 profile, with Set-Theme Paradox, on Windows 10 1909.

Desired Outcome oh-my-posh's impact on Powershell startup time should be reduced.

One possible way could be to reduce the dependency on posh-git - there might be several posh-git functions in there that are unused.

JanDeDobbeleer commented 4 years ago

I have a new engine that removes that dependency, but it's not ready for prime time just yet.

EvilVir commented 4 years ago

Yes, it's way too slow for daily use, at least for me :(

Maples7 commented 4 years ago

In addition, it's very slow for huge git codebase to show Git status indications. So for me, I have to abandon the Git status indications unwillingly. 😢

Maples7 commented 4 years ago

I've tried https://github.com/cmarcusreid/git-status-cache-posh-client and it could help to mitigate the problem.

PreetSangha commented 4 years ago

I've just installed the latest versions for the first time and unfortunately it's massively slow. Are there any tweaks I can use to make my prompt appear in a usable time please??

image

PreetSangha commented 4 years ago

I've just installed the latest versions for the first time and unfortunately it's massively slow. Are there any tweaks I can use to make my prompt appear in a usable time please??

image

Never mind. I've worked out that all I needed to do was install the modules for allusers in an elevated prompt and remove them from the profile. I've left commands commented out in my profile, viz.:

# run these from an elevated prompt and make sure that they are commented out here..
#Install-Module posh-git -scope AllUsers
#Install-Module oh-my-posh -scope AllUsers

Set-Theme agnoster

image

avezinaATastus commented 4 years ago

Installing as admin didn't change my startup speed @PreetSangha

PreetSangha commented 4 years ago

Installing as admin didn't change my startup speed @PreetSangha

so you installed the modules for all users? Did you remember to take the install-module commands out of your profile now? Note that I have them commented out in the above? I've edited the comment to make it clearer.

Preet

avezinaATastus commented 4 years ago

Yes. I don't have install-modules in my profile. I did remove the comment marks

PS> get-module oh-my-posh,posh-git -ListAvailable

Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands                                             
---------- -------    ----                                ----------------                                             
Script     2.0.443    oh-my-posh                          {Write-ColorPreview, Show-Colors, Show-ThemeColors, Show-T...
Script     0.7.3      posh-git                            {Invoke-NullCoalescing, Add-PoshGitToProfile, Get-PromptPa...
PreetSangha commented 4 years ago

What else do you have in your profile? Perhaps it's that that's taking the time?

JanDeDobbeleer commented 4 years ago

Hey @cardin. I just published my new engine. That one has no trouble with startup/rendering times.

You can install and use it as follows

Install-Module -Name go-my-posh -Repository PSGallery
Import-Module go-my-posh
Set-PoshPrompt paradox

if you want, you can also list all available themes

Get-PoshThemes

Feel free to create an issue there as well to follow up in case you find problems. I will keep an eye on oh-my-posh, but I'll favor go-my-posh going forward.

GF-Huang commented 3 years ago

So no solutions? I still took 800ms.

image

JanDeDobbeleer commented 3 years ago

@GF-Huang Set-Theme is V2, not V3. See https://ohmyposh.dev

GF-Huang commented 3 years ago

@GF-Huang Set-Theme is V2, not V3. See https://ohmyposh.dev

This?

[ScriptBlock]$Prompt = { $realLASTEXITCODE = $global:LASTEXITCODE & "C:\tools\oh-my-posh.exe" -config "~/downloadedtheme.json" -error $realLASTEXITCODE -pwd $PWD $global:LASTEXITCODE = $realLASTEXITCODE Remove-Variable realLASTEXITCODE -Confirm:$false } Set-Item -Path Function:prompt -Value $Prompt -Force

JanDeDobbeleer commented 3 years ago

You can easily update to the beta of oh-my-posh. https://ohmyposh.dev/docs/upgrading

nwykes commented 3 years ago

800ms is pretty fast? less than a second startup time seems reasonable.