starship: Starship is slow within rust directories

Current Behavior

In rust project directories starship takes a considerably longer about of time to re-appear as the prompt.

Expected Behavior

I would expect starship to be just as fast as in other directories.

Additional context/Screenshots

Screen Shot 2020-12-17 at 13 54 07

Environment

  • Starship version: 0.47.0
  • fish version: fish, version 3.1.2
  • Operating system: Mac OS 11.2.0
  • Terminal emulator: Alacritty

Relevant Shell Configuration

#!/usr/bin/env fish
set fish_greeting ""

fish_vi_key_bindings
set fish_cursor_default line
set fish_cursor_insert line
set fish_cursor_replace_one underscore
set fish_cursor_visual block
set -U __done_min_cmd_duration 5000  

alias :o='nvim'
alias git='hub'
alias :e='vim'
alias b='brew'
alias c='cargo'
alias ping='gping'
alias :q='exit'
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."
alias brewup='brew update; brew upgrade; brew upgrade --cask; brew cleanup; brew doctor'
alias cat='bat'
alias nat='natls -lgn'
alias ls='nat'
alias l='ls -h'
alias wclock='watch -n1 "date '+%D%n%T'|figlet -k"'
alias vim='nvim'
alias vi='nvim'
alias v='nvim'
alias rm='trash'
alias brave='open -a "/Applications/Brave Browser Dev.app/"'

set -x PATH $HOME/bin /usr/local/sbin /usr/local/bin /usr/bin /bin /usr/sbin /sbin $HOME/.cargo/bin $HOME/.projects/bin $HOME/Library/Python/2.7/bin $HOME/.local/bin $HOME/go/bin /usr/local/texlive/2020/bin/x86_64-darwin /usr/local/opt/qt/bin /usr/local/opt/python@3.9/bin $HOME/.deno/bin
source $HOME/.cargo/env
thefuck --alias | source
[ -f /usr/local/share/autojump/autojump.fish ]; and source /usr/local/share/autojump/autojump.fish
set -q GHCUP_INSTALL_BASE_PREFIX[1]; or set GHCUP_INSTALL_BASE_PREFIX $HOME
test -f /Users/willlane/.ghcup/env ; and set -gx PATH $HOME/.cabal/bin /Users/willlane/.ghcup/bin $PATH
set -Ux EDITOR nvim
set -Ux VISUAL nvim
zoxide init fish | source
eval (opam env)
starship init fish | source

Starship Configuration

[line_break]
disabled = true

[aws]
disabled = true

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 24 (13 by maintainers)

Most upvoted comments

Adding this here so it doesn’t get lost

talking with https://twitter.com/fasterthanlime, he suggested a potentially faster way for us to get rust’s runtime version without running rustc --version: head -1 "$(dirname $(rustup which rustc))/../share/man/man1/rustc.1"

I’m not exactly sure why this works but my shell lag reduced significantly after adding a ./rust-toolchain file with my version specified, so if you want to reduce shell lag this is something you can try. I don’t exactly understand what all this stuff means. I’m not a Rust developer so I don’t know what the ./rust-toolchain file does or what cargo is doing when it installs all those things or why the versions change to be Mac specific then back to generic after, but I do know that 34ms is noticeably better than 106ms. Not ideal (all other languages I use are <10ms) but better than nothing.

test-git-perf on 🌱master is 📦 v0.1.0 via 🦀 v1.57.0 
❯ starship timings

 Here are the timings of modules in your prompt (>=1ms or output):
 rust        -  106ms  -   via 🦀 v1.57.0 
 username    -    1ms  -   
 directory   -   <1ms  -   test-git-perf 
 git_branch  -   <1ms  -   on 🌱master 
 package     -   <1ms  -   is 📦 v0.1.0 
 line_break  -   <1ms  -   \n
 character   -   <1ms  -   ❯ 
test-git-perf on 🌱master is 📦 v0.1.0 via 🦀 v1.57.0 
❯ echo 1.57.0 > ./rust-toolchain
test-git-perf on 🌱master is 📦 v0.1.0 via 🦀 1.57.0-x86_64-apple-darwin 
❯ 
test-git-perf on 🌱master is 📦 v0.1.0 via 🦀 1.57.0-x86_64-apple-darwin 
❯ starship timings

 Here are the timings of modules in your prompt (>=1ms or output):
 rust        -  16ms  -   via 🦀 1.57.0-x86_64-apple-darwin 
 username    -   2ms  -   
 directory   -   1ms  -   test-git-perf 
 git_branch  -  <1ms  -   on 🌱master 
 package     -  <1ms  -   is 📦 v0.1.0 
 line_break  -  <1ms  -   \n
 character   -  <1ms  -   ❯ 
test-git-perf on 🌱master is 📦 v0.1.0 via 🦀 1.57.0-x86_64-apple-darwin 
❯ cargo run
info: syncing channel updates for '1.57.0-x86_64-apple-darwin'
info: latest update on 2021-12-02, rust version 1.57.0 (f1edd0429 2021-11-29)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: installing component 'rustfmt'
    Finished dev [unoptimized + debuginfo] target(s) in 2.15s
     Running `target/debug/test-git-perf`
Changes found
test-git-perf on 🌱master is 📦 v0.1.0 via 🦀 v1.57.0 took 15s 
❯ 
test-git-perf on 🌱master is 📦 v0.1.0 via 🦀 v1.57.0 
❯ starship timings

 Here are the timings of modules in your prompt (>=1ms or output):
 rust        -  34ms  -   via 🦀 v1.57.0 
 username    -   2ms  -   
 directory   -   1ms  -   test-git-perf 
 git_branch  -  <1ms  -   on 🌱master 
 package     -  <1ms  -   is 📦 v0.1.0 
 line_break  -  <1ms  -   \n
 character   -  <1ms  -   ❯ 

@Rajendrasinh-AI Yeah I also have it disabled right now

Unfortunately I’m not aware of any other ways to query the version other than, say, reimplementing the version querying part in rustup.

And there doesn’t seem to be any prior art to get inspiration from, as the prompts are possibly the only existing program that needs fast output for version info.

But we may just ask the rustup devs and see if they have any better ideas.

Unfortunately, that’s not how starship is set up :\

Starship runs once every time the prompt is drawn. This is basically the only way that we know of to run starship without getting into particulars of daemonization of processes across many different platforms, but it also means that caching things between invocations gets a little tricky. It took a bit of hackery just to get per-session warnings working correctly.

In addition, I think there’s a concern with correctness in the case of rustup, because exec_rustc_version() has to be run once per directory. I’m allowed to change the rustup toolchain in a directory via rustup override, so the rustc version that’s valid in one project may be wrong in another (e.g. right now I’m working through the CS3210 course at GATech, and I have to use 1.37-nightly for that, so in that directory, the version is 1.37.0-nightly and in my other directories, it’s the stable version).