starship: Starship is slow on PowerShell in Windows

Current Behavior

Any prompt takes up to 2 seconds to display regardless of environment or current directory, without any modules enabled.

Expected Behavior

It should work way more faster

Additional context/Screenshots

~
❯ Measure-Command { starship explain }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 1
Milliseconds      : 560
Ticks             : 15604482
TotalDays         : 1.80607430555556E-05
TotalHours        : 0.000433457833333333
TotalMinutes      : 0.02600747
TotalSeconds      : 1.5604482
TotalMilliseconds : 1560.4482

~
❯ starship explain

 Here's a breakdown of your prompt:
 ~  (45ms)  -  The current working directory
 ❯  (<1ms)  -  A character (usually an arrow) beside where the text is entered in your terminal

Possible Solution

Unfortunately I don’t know Rust yet and the only thing I was able to do is to build a binary and run it with trace logging enabled, but it doesn’t really help.

starship.log

Environment

  • Starship version: 0.47.0
  • powershell version: 7.1.0
  • Operating system: Windows 10.0.18363
  • Terminal emulator: Windows Terminal

Relevant Shell Configuration

Invoke-Expression (&starship init powershell)

Starship Configuration

[git_status]
disabled = true

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 20 (8 by maintainers)

Most upvoted comments

I have finally resolved the issue. It wasn’t starship prompt at all (: It was antivirus software. It has real-time protection and it’s triggered by starship and powershell binaries each time new prompt has to be displayed. The most tricky part is that you have to exclude two binaries from those checks:

  • C:\ProgramData\chocolatey\bin\starship.exe;
  • C:\Program Files\PowerShell\7\pwsh.exe

Excluding just starship.exe doesn’t help even though Measure-Command { starship explain starts to show great timings. Remember to exclude pwsh.exe also!

You can speed up startup in PowerShell a bit by using &starship init powershell --print-full-init | Out-String | Invoke-Expression instead of Invoke-Expression (&starship init powershell). (#1032 #2637)

Edit: I made a PR (#2146) to improve performance in WSL by using windows starship for windows paths.

Loading personal and system profiles took 1622ms.
$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.0
PSEdition                      Core
GitCommitId                    7.2.0
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
starship explain

 Here's a breakdown of your prompt:
 ">" (<1ms)                 -  A character (usually an arrow) beside where the text is entered in your terminal
 "~ " (1ms)                 -  The current working directory
 " " (<1ms)                 -  Fills the remaining space on the line with a pad string
 "computer] " (<1ms)    -  The system hostname
 "10:12 " (<1ms)            -  The current local time
 "[name@" (<1ms)  -  The active user's username
starship timings

 Here are the timings of modules in your prompt (>=1ms or output):
 battery     -  16ms  -   ""
 hg_branch   -   5ms  -   ""
 git_branch  -   4ms  -   ""
 package     -   1ms  -   ""
 directory   -   1ms  -   "~ "
 character   -  <1ms  -   ">"
 fill        -  <1ms  -   " "
 hostname    -  <1ms  -   "computer] "
 time        -  <1ms  -   "10:17 "
 username    -  <1ms  -   "[name@"
Measure-Command { starship explain }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 1
Milliseconds      : 203
Ticks             : 12039658
TotalDays         : 1.39347893518519E-05
TotalHours        : 0.000334434944444444
TotalMinutes      : 0.0200660966666667
TotalSeconds      : 1.2039658
TotalMilliseconds : 1203.9658

Measure-Command { starship init powershell }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 1
Milliseconds      : 207
Ticks             : 12076243
TotalDays         : 1.39771331018519E-05
TotalHours        : 0.000335451194444444
TotalMinutes      : 0.0201270716666667
TotalSeconds      : 1.2076243
TotalMilliseconds : 1207.6243

Modules are fast enough but loading the next prompt is always taking forever. starship timings aren’t accurate at all as to how fast the next prompt is loading, it is always > 1 second. It’s like it is running starship init after every command or something

Well wherever you’re getting the slowdown appears to be outside the modules, they don’t seem to have any issues.