Skip to content

Opening Github Desktop on MacOS results in High CPU usage #12320

Closed

Description

@ed9w2in6

Describe the bug

Opening Github Desktop on MacOS results in High CPU usage, possibly
due to shelling out to collect environment variables.

Version & OS

GitHub Desktop: Version 2.8.2 (x64)
OS: MacOS 11.4(20F71)

Steps to reproduce the behavior

  1. Open Github Desktop.
  2. do ps aux | grep zsh and observed the dangling /bin/zsh -ilc command env processes.

Expected behaviour

Expected behaviour: No dangling zsh processes.

Actual behavior

Actual behaviour: 4 dangling zsh processes.

Screenshots

Output of ps aux | grep zsh:

❯ ps aux | grep --color=auto zsh
username      86402 100.0  0.0  4307012    772   ??  R     1:56下午   0:12.56 /bin/zsh -ilc command env
username      86393 100.0  0.0  4324420    784   ??  R     1:56下午   0:13.16 /bin/zsh -ilc command env
username      80244   0.1  0.0  4337276   6224 s000  S    12:23下午   0:08.67 -zsh
username      86483   0.0  0.0  4277640    744 s000  S+    1:56下午   0:00.00 grep --color=auto zsh
username      86397   0.0  0.0  4298036   1464   ??  Ss    1:56下午   0:00.01 /bin/zsh -ilc command env
username      86387   0.0  0.0  4324660   1504   ??  Ss    1:56下午   0:00.01 /bin/zsh -ilc command env

Logs

Attach your logs by opening the Help menu and selecting Show Logs..., if applicable.

Additional context

Similar problem with Atom ( also using electron ): atom/atom --- issue#22507
,atom/atom --- issue#13317, and atom/atom --- issue#13084.

This may be a problem with Electron but But not necessary as Discord does not have the same problem.

Activity

  1. sergiou87 commented on May 31, 2021

    @sergiou87
    Member

    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 🤔

  2. added
    more-info-needed
    on May 31, 2021
  3. ed9w2in6 commented on May 31, 2021

    @ed9w2in6
    Author

    @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?

  4. removed
    more-info-needed
    on May 31, 2021
  5. sergiou87 commented on May 31, 2021

    @sergiou87
    Member

    @ed9w2in6 does it only happen when you run the github command? Or also when you open the app normally from the Dock or Spotlight or /Applications?

  6. added
    more-info-needed
    on May 31, 2021
  7. ed9w2in6 commented on May 31, 2021

    @ed9w2in6
    Author

    @sergiou87 The issue can be triggered by launching Github Desktop in all of the methods that you had mentioned.

  8. removed
    more-info-needed
    on May 31, 2021
  9. ed9w2in6 commented on May 31, 2021

    @ed9w2in6
    Author

    I found where the code can be changed if the maintainers thinks the change is needed. ( near line 60 )

  10. sergiou87 commented on Jun 1, 2021

    @sergiou87
    Member

    @ed9w2in6 I asked about that because, in theory, it should only invoke that zsh -ilc command env when it's not launched from the command line:

    /**
    * Inspect whether the current process needs to be patched to get important
    * environment variables for Desktop to work and integrate with other tools
    * the user may invoke as part of their workflow.
    *
    * This is only applied to macOS installations due to how the application
    * is launched.
    *
    * @param process The process to inspect.
    */
    export function shellNeedsPatching(process: NodeJS.Process): boolean {
    return __DARWIN__ && !process.env.PWD
    }

    From your .zshrc, what's precmd exactly? Just adding print -Prn $PROMPT to my .zshrc I couldn't reproduce the issue.

  11. added
    more-info-needed
    on Jun 1, 2021
  12. ed9w2in6 commented on Jun 5, 2021

    @ed9w2in6
    Author

    @sergiou87 Thanks for your reply.

    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-ps1
    prompt-length() {  
        emulate -L zsh
        local -i COLUMNS=${2:-COLUMNS}
        local -i x y=${#1} m #MAX_acc=1000 acc=1  
        if (( y )); then
            while (( ${${(%):-$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 ))
            done
        fi  
        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.

  13. removed
    more-info-needed
    on Jun 5, 2021
  14. added
    macOS
    on Aug 23, 2021
  15. steveward commented on Sep 18, 2024

    @steveward
    Contributor

    I'm going to close this out in favor of our broader tracking issue (#10625), as we too many scattered issues around performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    macOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions