Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agnoster theme prompt extremly slow in mercurial #4116

Closed
MerliX opened this issue Jul 2, 2015 · 24 comments
Closed

Agnoster theme prompt extremly slow in mercurial #4116

MerliX opened this issue Jul 2, 2015 · 24 comments
Labels
Area: theme Issue or PR related to a theme Enhancement Improved user experience

Comments

@MerliX
Copy link

MerliX commented Jul 2, 2015

Code here https://github.com/robbyrussell/oh-my-zsh/blob/3d2bf227ea2b37d351ac3846627f28151e0a4480/themes/agnoster.zsh-theme#L111 runs very slow (mac yosemite)

@apjanke
Copy link
Contributor

apjanke commented Jul 2, 2015

FYI, if you're going to link to lines of code (or files for that matter) in a bug report, you should link to a specific commit, instead of "master" or another branch name. Otherwise, later commits may shift around line numbers and your link will be pointing at a different piece of code. (For example, we're about to merge a commit to agnoster that will probably shift everything down a few lines, and your link will be pointing in to the zstyle commands inside prompt_git.)

https://github.com/robbyrussell/oh-my-zsh/blob/3d2bf227ea2b37d351ac3846627f28151e0a4480/themes/agnoster.zsh-theme#L111

@MerliX
Copy link
Author

MerliX commented Jul 3, 2015

@apjanke thanks for advice

@apjanke
Copy link
Contributor

apjanke commented Jul 3, 2015

How slow is "extremely slow" for you? This stuff is all relative. :)

I'm trying it out on OS X 10.9.5 Mavericks, on an SSD MacBook Pro. In a newly created Hg repo, it feels like it takes between half a second and a second to issue the prompt. That feels pretty slow to me. But is also not a huge surprise: this is not a very fast theme, and it's doing hg shellouts.

This could maybe be improved by consolidating the hg calls and doing parsing with native zsh string stuff afterwards. And the hg prompt test could be done once at theme load time.

@apjanke
Copy link
Contributor

apjanke commented Jul 3, 2015

Oh, yeah, we can totally speed this up. Half those hg calls are unnecessary. I'll give it a try when I have some free time, maybe later today.

@MerliX
Copy link
Author

MerliX commented Jul 3, 2015

I did a quick fix for this, but it is not so functional. However, probably it will help

prompt_hg() {
  local rev_branch st hg_status
  rev_branch=$(hg id -n -b 2>/dev/null)

  if [ ! -z "$rev_branch" ] ; then
    st=""
    hg_status=`hg st`
    if `echo $hg_status | grep -q "^\?"`; then
      prompt_segment red black
      st='±'
    elif `echo $hg_status | grep -q "^[MA]"`; then
      prompt_segment yellow black
      st='±'
    else
      prompt_segment green black
    fi
    echo -n "☿ $rev_branch" $st
  fi
}

By the way, I switched my console to https://github.com/bhilburn/powerlevel9k witch is way more fast from-the-box

@apjanke
Copy link
Contributor

apjanke commented Jul 3, 2015

Thanks!

Interesting. PowerLevel9K is relying entirely on zsh's own vcs_info for the Hg stuff, instead of rolling its own. I'll look in to that and see if it's an option for us, too.

@dritter
Copy link
Contributor

dritter commented Jul 10, 2015

@apjanke Jep. vcs_info uses mostly hexdump to get the information from the repository and invokes mercurial only once.

@apjanke
Copy link
Contributor

apjanke commented Jul 11, 2015

Oh, nice. I see some vcs_info in my future, in that case.

@apjanke
Copy link
Contributor

apjanke commented Nov 6, 2015

Agnoster now has its own repo, https://github.com/agnoster/agnoster-zsh-theme, and is using Zsh vcs_info. Can you give the upstream theme a try and see if it's still slow for you?

@MerliX
Copy link
Author

MerliX commented Nov 9, 2015

Well, its not slow anymore, but it neither shows hg info in zsh prompt =) Built-in agnoster theme is still slow in hg repo. I am happy with powerlevel9k theme by the way

@apjanke
Copy link
Contributor

apjanke commented Nov 9, 2015

Oh yeah, the hg support was an OMZ addition. Nevermind about asking upstream. :)

@Cypher1
Copy link
Contributor

Cypher1 commented Jan 24, 2017

Will this improve anytime soon? I'm having similar issues with bullettrain (which is based on agnoster).
I'm having multiple seconds of waiting time between prompt renders in a largish hg repo.

@caugner
Copy link
Contributor

caugner commented Sep 14, 2017

Steps to reproduce:

hg clone https://hg.mozilla.org/mozilla-central
cd mozilla-central
time (prompt_hg > /dev/null)
# ( prompt_hg > /dev/null; )  2.77s user 1.19s system 99% cpu 3.971 total 

@caugner
Copy link
Contributor

caugner commented Sep 14, 2017

The lag stems from the three calls to hg id on lines 155 and 172/173 and hg st on line 174/177:

hg clone https://hg.mozilla.org/mozilla-central
cd mozilla-central

time hg id
# hg id  0.66s user 0.35s system 99% cpu 1.020 total

time hg id -n
# hg id -n  0.65s user 0.38s system 99% cpu 1.032 total

time hg id -b
# hg id -b  0.08s user 0.03s system 99% cpu 0.117 total

time hg st
# hg st  1.32s user 0.41s system 99% cpu 1.733 total

@caugner
Copy link
Contributor

caugner commented Sep 14, 2017

In theory, there is some potential:

hg clone https://hg.mozilla.org/mozilla-central
cd mozilla-central
  1. Replace hg id with hg root:
# hg id  0.70s user 0.40s system 99% cpu 1.103 total
# hg root  0.10s user 0.04s system 99% cpu 0.137 total
  1. Replace double hg st with single ( hg st -uma | cut -c -1 | sort | uniq | paste -d, -s; )
# hg st  1.29s user 0.43s system 16% cpu 10.316 total
# ( hg st -uma | cut -c -1 | sort | uniq | paste -d, -s; )  1.36s user 0.42s system 101% cpu 1.758 total
  1. Replace hg id -n and hg id -b with single hg id -nb
# hg id -n  0.69s user 0.39s system 99% cpu 1.076 total
# hg id -b  0.10s user 0.03s system 99% cpu 0.124 total
# hg id -nb  0.66s user 0.39s system 99% cpu 1.057 total

In practice, this does improve the situation only slightly:

# Before
# ( prompt_hg > /dev/null; )  2.86s user 1.27s system 99% cpu 4.138 total
# After
# ( prompt_hg > /dev/null; )  2.17s user 0.87s system 100% cpu 3.024 total

@maelvls
Copy link

maelvls commented Jan 4, 2018

Wow, using chg instead of hg (just put alias hg=chg in your .zshrc) seems to make prompt_hg as fast as the git prompt!

Any drawbacks? I guess it is only available on the latest hg versions?

Update: I realized that a ~12MB Python process has to be kept running in background (but I guess I don't mind)

@caugner
Copy link
Contributor

caugner commented Apr 25, 2018

I guess it is only available on the latest hg versions?

@maelvalais What version of hg do you run? Unfortunately, chg is not available for me in Mercurial 4.3.2.

@sylvestre
Copy link

Looks like it is https://www.mercurial-scm.org/wiki/CHg (afaik, not shipped with mercurial)
And indeed, the mercurial extension isn't usable on large repo like Firefox...

@maelvls
Copy link

maelvls commented Sep 5, 2018

Ahh... I just noticed that this chg is in contrib/ and thus probably not compiled/installed by default by standard package managers. The reason I have it is that Homebrew installs chg by default (see formula).

Unfortunate that it is not shipped by default...

@caugner
Copy link
Contributor

caugner commented Sep 6, 2018

I have disabled the status in mercurial repositories now by adding functions[prompt_hg]="" to my .zshrc.

jonas-schulze added a commit to jonas-schulze/dotfiles that referenced this issue Oct 15, 2018
The agnoster theme still seems to be really slow in Mercurial repos.
I tried the custom repo of anoster, which out of the box was no better.
So let's give powerlevel9k a try.

ohmyzsh/ohmyzsh#4116
@Ilphrin
Copy link

Ilphrin commented Nov 7, 2018

Hi!

Is there any news about this issue? I have the exact same problem with firefox repository with agnoster theme prompt.

@nagyf
Copy link

nagyf commented Nov 22, 2018

Just checking in, I'm experiencing the same problem with agnoster theme and the mozilla unified repository...
caugner's solution is a great workaround

@mcornella mcornella added Area: theme Issue or PR related to a theme Enhancement Improved user experience and removed Plugin: mercurial labels Apr 9, 2019
@yagehu
Copy link

yagehu commented Aug 8, 2020

I have disabled the status in mercurial repositories now by adding functions[prompt_hg]="" to my .zshrc.

Is there a way to disable mercurial prompt just for a repository? Similar to git config oh-my-zsh.hide-status 1.

@mcornella mcornella moved this to Backlog in Main project Jan 2, 2022
@robbyrussell
Copy link
Member

Going to close this and assume any edgecases can be sorted with a per-project workaround

@github-project-automation github-project-automation bot moved this from Backlog to Done in Main project Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: theme Issue or PR related to a theme Enhancement Improved user experience
Projects
Archived in project
Development

No branches or pull requests