JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
15.83k stars 2.28k forks source link

Improve performance for git prompts (on PowerShell) #4880

Open brian6932 opened 2 months ago

brian6932 commented 2 months ago

Code of Conduct

What would you like to see changed/added?

posh-git's not really maintained, there has been an open PR to improve the git status performance for quite some time (https://github.com/dahlbyk/posh-git/pull/924). It's currently extremely sluggish (yes even with "ignore_submodules":{"*":"none"}). Realistically to have consistent performance across all supported shells, it would be nice for oh-my-posh to have it's own git status handling, either with git-status-cache or with it's own cache. Since that's a bit more involved, a quick solution for now would be to use https://github.com/zhengweidi/git-status-cache-posh-client/tree/master with https://github.com/zhengweidi/git-status-cache/tree/master, or something like gitstatusd https://github.com/romkatv/gitstatus.

ivan-the-terrible commented 2 months ago

Currently doing some reading about this. I like the note that's here on romkatv gitstatus README's Why Fast. This does make a lot of sense and I might seek to replicate the scenario used in the benchmarks.

I also understand the idea behind the PRs you listed from posh-git PR 924 using Get-GitConciseStatusFromCache (which is defined here).

There is a oh-my-posh does have a cache declared within the JSON file at AppData\Local\oh-my-posh\omp.cache. image

Here is the setGitStatus function where the cache might be implemented:

image

Will dig further into the codebase to see what can be done and maybe put out a PR.

ivan-the-terrible commented 2 months ago

@brian6932 what would be really cool is if there is a Go package available with the logic :) If you could poke around to find one, that would be extremely helpful.

brian6932 commented 2 months ago

There's https://github.com/go-git/go-git I guess, you'd have to implement the caching on top of it, or just use the code from https://github.com/go-git/go-git/blob/master/status.go and work from there, as it'd reduce dependencies.

JanDeDobbeleer commented 2 months ago

Go git is terribly slow, tried it before. I don't mind adding support for existing cache tools, I'm not in favor of adding logic that aims to do what git itself should improve (faster status).

brian6932 commented 2 months ago

I found starship (which uses gitoxide) to have a relatively performant git status prompt (https://github.com/mcwarman/starship/tree/feature/detailed-github-status), only thing's that submodules have to be disabled ([git_status] ignore_submodules = true), or else it becomes extremely slow, so it's definitely not impossible to parse git status from .git quicker.

JanDeDobbeleer commented 2 months ago

@brian6932 check, but as a maintainer, I need to be careful how far this can get pushed. And that's an implementation where I want to be in the lead so I can also keep offering support. It's not easy or straightforward or git would've fixed it already.