Skip to content

git_prompt_status is slow on cygwin #5486

@TheDauthi

Description

@TheDauthi

git_prompt_status is rather slow on cygwin, and on other platforms where spawning a subshell is slow.
Two cases:
(first, just calling the function, second is inside a fresh linux kernel tree. )

TheDauthi@Hera:~$ time (git_prompt_status)
( git_prompt_status; )  0.21s user 0.41s system 97% cpu 0.636 total
TheDauthi@Hera:~/Projects/linux$ time (git_prompt_status)
( git_prompt_status; )  2.41s user 9.50s system 228% cpu 5.216 total

(Not much we can do about the second one, it's due to the slowness of the git status itself)
Identical setup on linux:

billyconn@Hades:~$ time (git_prompt_status)
( git_prompt_status; )  0.00s user 0.01s system 16% cpu 0.047 total
billyconn@Hades:~/Projects/linux$ time (git_prompt_status)
( git_prompt_status; )  0.06s user 0.08s system 85% cpu 0.173 total

Tracking this down, it's the spawning of the greps (which is no shock; cygwin emulation of fork is well-known, and grep is somehow particularly slow). I rewrote this function to use zsh builtins and an ugly bit of sed instead of spawning greps:

Cygwin:

TheDauthi@Hera:~$ time (git_prompt_status)
( git_prompt_status; )  0.07s user 0.04s system 117% cpu 0.102 total
TheDauthi@Hera:~/Projects/linux$ time (git_prompt_status)
( git_prompt_status; )  2.30s user 8.75s system 241% cpu 4.567 total

It's faster on linux, too, but linux was already fast:
Linux:

billyconn@Hades:~$ time (git_prompt_status)           
( git_prompt_status; )  0.00s user 0.00s system 0% cpu 0.008 total
billyconn@Hades:~/Projects/linux$ time (git_prompt_status)
( git_prompt_status; )  0.06s user 0.09s system 104% cpu 0.137 total

https://github.com/TheDauthi/git-prompt-status

I didn't make a pull request; this is in a frequently-used lib so I didn't want to touch it without testing, if there's even interest in using a modified version. I wrote a FEW tests (they're in the test directory), but will try to add more. I also would like to know if/how you typically integrate tests, as what's there is just something I hacked up in a couple of hours.

Not sure how the command works on OSX yet, don't have a machine to test on until Monday. I suspect that the sed statements will need to be re-quoted. Wanted to gauge interest and get feedback before continuing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: themeIssue or PR related to a themeBugSomething isn't workingPerformanceIssue or PR about performancePlatform: WindowsIssue or PR for Windows

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions