You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Opening Github Desktop on MacOS results in High CPU usage #12320
Weird, I can't reproduce this behavior. Have you tried running the app with a clean .zshrc? I wonder if there is something in your .zshrc that could case that command to get stuck like that 🤔
@sergiou87 I found the cause for the bug, in my .zshrc file I did:
# make zsh appears to load faster.
precmd
print -Prn $PROMPT
I made zsh's interactive command prompt prints stuff on startup to make it appears to load up quicker ( inspired by powerlevel10k ), and that upsets the Github app in which it doesn't terminate.
I can solve the problem by printing to /dev/stderr instead of /dev/stdout at the moment. Please ignore the texts above.
Sorry, I simply did not close the Github Desktop app before I rerun github command.
The problem cannot be solved without removing the text printing commands.
However, I don't think that it is not acceptable to print stuff to stdout in .zshrc, since it is supposed to be sourced for interactive prompt only.
I think an App or script should be running /bin/zsh -lc command env instead of /bin/zsh -ilc command env, or perhaps allowing one to disable the shelling out behaviour as an option. Is that not possible for the use case of Github Desktop?
Interesting. Well I tested my precmd and it seems that this is keeping zsh alive:
# Took from: https://superuser.com/questions/357107/zsh-right-justify-in-ps1prompt-length() {
emulate -L zsh
local -i COLUMNS=${2:-COLUMNS}local -i x y=${#1} m #MAX_acc=1000 acc=1 if(( y ));thenwhile((${${(%):-$1%$y(l.1.0)}[-1]}));do
x=y
(( y *=2))# (( acc += 1 ))done# unset acc;# local -i acc=1;while(( y > x +1));do(( m = x + (y - x) /2))((${${(%):-$1%$m(l.x.y)}[-1]}= m ))# (( acc += 1 ))donefi
print "$x"
}
The function is used to allow one to create a multi-lined left and right aligned PROMPT.
The logic of cryptic lines like: ${${(%):-$1%$y(l.1.0)}[-1]} is to first do PROMPT expansion ( like colours, etc. ) for $1, then
see if its length is less then the integer in $y, append '1' to $1, else append '0'. [-1] extract the trailing 0 or 1.
The rest should be fairly readable.
The code is basically a binary search to determine the length of the interpolated string.
I had tried to make sure the loop terminates by setting a maximum amount of iteration, but they do nothing so I commented them out / removed them. The loop should always terminate regardless, which it does, as a matter of fact I am using it daily with no issues. For some reason the behaviour is different when the shell is spawned by child_process.
I am puzzled with this.
At the moment, bypassing this function on startup seems to have stopped the issue from happening.
Activity
sergiou87 commentedon May 31, 2021
Weird, I can't reproduce this behavior. Have you tried running the app with a clean .zshrc? I wonder if there is something in your .zshrc that could case that command to get stuck like that 🤔
ed9w2in6 commentedon May 31, 2021
@sergiou87 I found the cause for the bug, in my
.zshrcfile I did:I made zsh's interactive command prompt prints stuff on startup to make it appears to load up quicker ( inspired by powerlevel10k ), and that upsets the Github app in which it doesn't terminate.
I can solve the problem by printing to/dev/stderrinstead of/dev/stdoutat the moment.Please ignore the texts above.
Sorry, I simply did not close the Github Desktop app before I rerun
githubcommand.The problem cannot be solved without removing the text printing commands.
However, I don't think that it is not acceptable to print stuff to
stdoutin.zshrc, since it is supposed to be sourced for interactive prompt only.I think an App or script should be running
/bin/zsh -lc command envinstead of/bin/zsh -ilc command env, or perhaps allowing one to disable the shelling out behaviour as an option. Is that not possible for the use case of Github Desktop?sergiou87 commentedon May 31, 2021
@ed9w2in6 does it only happen when you run the
githubcommand? Or also when you open the app normally from the Dock or Spotlight or/Applications?ed9w2in6 commentedon May 31, 2021
@sergiou87 The issue can be triggered by launching Github Desktop in all of the methods that you had mentioned.
ed9w2in6 commentedon May 31, 2021
I found where the code can be changed if the maintainers thinks the change is needed. ( near line 60 )
sergiou87 commentedon Jun 1, 2021
@ed9w2in6 I asked about that because, in theory, it should only invoke that
zsh -ilc command envwhen it's not launched from the command line:desktop/app/src/lib/shell.ts
Lines 15 to 27 in bca5aa4
From your
.zshrc, what'sprecmdexactly? Just addingprint -Prn $PROMPTto my.zshrcI couldn't reproduce the issue.ed9w2in6 commentedon Jun 5, 2021
@sergiou87 Thanks for your reply.
Interesting. Well I tested my
precmdand it seems that this is keeping zsh alive:The function is used to allow one to create a multi-lined left and right aligned PROMPT.
The logic of cryptic lines like:
${${(%):-$1%$y(l.1.0)}[-1]}is to first do PROMPT expansion ( like colours, etc. ) for$1, thensee if its length is less then the integer in
$y, append'1'to$1, else append'0'.[-1]extract the trailing0or1.The rest should be fairly readable.
The code is basically a binary search to determine the length of the interpolated string.
I had tried to make sure the loop terminates by setting a maximum amount of iteration, but they do nothing so I commented them out / removed them. The loop should always terminate regardless, which it does, as a matter of fact I am using it daily with no issues. For some reason the behaviour is different when the shell is spawned by
child_process.I am puzzled with this.
At the moment, bypassing this function on startup seems to have stopped the issue from happening.
steveward commentedon Sep 18, 2024
I'm going to close this out in favor of our broader tracking issue (#10625), as we too many scattered issues around performance.