oh-my-fish / theme-agnoster

MIT License
96 stars 64 forks source link

Added an option to selectively enable hg prompt #68

Closed kylosus closed 1 year ago

kylosus commented 1 year ago

prompt_hg is slowing down my prompt significantly on my machine (around 2 seconds of delay) on all directories. This PR adds a theme_mercurial_prompt_enabled option similar to svn settings, and only leaves git enabled by default.

WBTMagnum commented 1 year ago

I had the same issue. Prompt for all directories where extremely slow using hg-prompt. If I recall correctly it was a configuration error and HG tried to scan the wrong / all folders. Unfortunately I could not find any notes on the issue. Maybe that gives a clue for a better solution than disabling per hg-prompt default ;-).

Cheers, Sascha

kylosus commented 1 year ago

It would indeed be better to fix the underlying issue making prompt_hg slow, but I think it's still worthwhile to have an option to disable it completely. I only care about git myself, and other prompts only introduce undue latency for me.

I'm not familiar with hg, so someone else more qualified should debug it.

It seems to be a regression introduced sometime after 43860ce1536930bca689470e26083b0a5b7bd6ae, as I have another machine with older omf and agnoster without performance issues. Nevermind, I just didn't have mercurial installed there.

faho commented 1 year ago

Since fish 3.0 it ships a function called fish_print_hg_root that can be used to figure out if something is an hg repo without actually calling hg. This is used by fish's hg prompt.

This should typically take a millisecond or so, in contrast to hg id, which takes ~200ms hot cache on my machine (like basically any hg command - it has very high startup costs).

So you could do

type -q hg; and fish_print_hg_root >/dev/null; and prompt_hg

and massively speed up all prompts outside of hg repos, which should be an easy win for everyone.

Unfortunately I don't have high hopes you'll get it merged here as the maintainers are inactive.

kylosus commented 1 year ago

Thanks for the suggestion, I modified prompt_hg to minimize expensive calls to hg, though it's still not perfect and I'm not interested enough in mercurial to optimize it further.

sn0cr commented 1 year ago

@kylosus Thank you for your contribution. I actually also don't use Mercurial at all, so thank you for the optimisation for all other users!