{"thread":{"id":"45119","subject":"Git status performance on PS (command prompt)","startedAt":"2017-02-12T15:54:13Z","lastAt":"2017-02-13T06:12:51Z","messageCount":3,"participants":["Mark Gaiser","brian m. carlson","Christian Couder"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"311360","messageId":"CAPd6JnGC3yeDo_sB+H+UKvh-PbiC2qySC=EbaRNLbkkwYkJM4A@mail.gmail.com","threadId":"45119","inReplyTo":null,"subject":"Git status performance on PS (command prompt)","fromName":"Mark Gaiser","fromEmail":"markg85@gmail.com","sentAt":"2017-02-12T15:53:47Z","receivedAt":"2017-02-12T15:54:13Z","isPatch":false,"sender":{"key":"markg85@gmail.com","avatar":null},"body":"Hi,\n\nI'm using ZSH with some fancy prompt. In that prompt is also a quick\ngit status overview (some symbols indicating if the branch is up to\ndate, if there are changes, etc..\n\nThe commands that are being executed to fetch the information:\n\nFor the file status:\ngit status --porcelain\n\nFor the repository status:\ngit status --porcelain -b\n\nOn small repositories (or even medium sized ones) this is fast, no\nproblems there.\nBut on larger repositories this is notably slow (i'm taking QtBase as\nan example now, but the same is true for much of the Qt repositories,\nor chromium or even the linux kernel itself). It's no problem if it's\nslow when you do \"git status\" on the command line. That can be\nexpected to take a little while on large repositories. But in zsh\nprompts the call to git isn't asynchronous [1] so any slowdown will be\nnoticed as the prompt simply doesn't completely show till after the\ncommand.\n\nI did a bit of profiling in git to figure out where this slowdown comes from.\nCallgrind tells me that \"read_directory_recursive\" takes up ~62% of the time.\nWithin that call the function \"last_exclude_matching_from_list\" takes\nup 49% of the time it takes to run \"git status --porcelain -b\".\n\nI don't really know how this code is supposed to work (i'm a git user,\nnot a git developer), so i hope someone might be able to investigate\nthis further. I can however apply patches to git locally and help out\nwith testing.\n\nAlso, is there perhaps a command out there that might be better suited\nfor the git status i want to show in the prompt? What i have now is\nmerely from one of the oh-my-zsh themes.\n\nBest regards,\nMark\n\np.s. please keep me in cc, i'm not subscribed to this list.\n\n[1] Most prompts don't have async support, but there are prompts that\ndo provide this: https://github.com/sindresorhus/pure I guess that\nwould be a better solution for me in the short term. Still, having the\nstatus being made faster would be beneficial.\n"},{"id":"311362","messageId":"20170212164650.u7frv234kmu5hm7r@genre.crustytoothpaste.net","threadId":"45119","inReplyTo":"CAPd6JnGC3yeDo_sB+H+UKvh-PbiC2qySC=EbaRNLbkkwYkJM4A@mail.gmail.com","subject":"Re: Git status performance on PS (command prompt)","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-12T16:46:50Z","receivedAt":"2017-02-12T16:47:03Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Sun, Feb 12, 2017 at 04:53:47PM +0100, Mark Gaiser wrote:\n> Hi,\n> \n> I'm using ZSH with some fancy prompt. In that prompt is also a quick\n> git status overview (some symbols indicating if the branch is up to\n> date, if there are changes, etc..\n> \n> The commands that are being executed to fetch the information:\n> \n> For the file status:\n> git status --porcelain\n> \n> For the repository status:\n> git status --porcelain -b\n\nSo your prompt is running git status twice?  Wouldn't it make more sense\nto just run it once and do a head -n 1 to filter out the branch when you\nneed it?  git symbolic-ref HEAD might work as well.\n\n> On small repositories (or even medium sized ones) this is fast, no\n> problems there.\n> But on larger repositories this is notably slow (i'm taking QtBase as\n> an example now, but the same is true for much of the Qt repositories,\n> or chromium or even the linux kernel itself). It's no problem if it's\n> slow when you do \"git status\" on the command line. That can be\n> expected to take a little while on large repositories. But in zsh\n> prompts the call to git isn't asynchronous [1] so any slowdown will be\n> noticed as the prompt simply doesn't completely show till after the\n> command.\n> \n> I did a bit of profiling in git to figure out where this slowdown comes from.\n> Callgrind tells me that \"read_directory_recursive\" takes up ~62% of the time.\n> Within that call the function \"last_exclude_matching_from_list\" takes\n> up 49% of the time it takes to run \"git status --porcelain -b\".\n\nThis isn't entirely surprising.  When git status runs, it checks all the\nfiles to see if the stat information is changed, and if so, updates the\nstatus.  last_exclude_matching_from_list determines if the files are\nignored, which is also necessary to ensure that only the proper files\nare listed.\n\nThat doesn't mean that there couldn't be some improvements there,\nthough.\n\n> I don't really know how this code is supposed to work (i'm a git user,\n> not a git developer), so i hope someone might be able to investigate\n> this further. I can however apply patches to git locally and help out\n> with testing.\n> \n> Also, is there perhaps a command out there that might be better suited\n> for the git status i want to show in the prompt? What i have now is\n> merely from one of the oh-my-zsh themes.\n\nI typically use the vcs_info support built into zsh[0], although that\ncan be very slow on my phone.  It performs adequately on most\nrepositories on my laptop and server machines, though, including on the\nLinux kernel repo and our 2.4 and 9 GB repos at work.\n\nI don't know that it has all the functionality that you need, as git\nstatus provides finer-grained data, but it might.\n\n[0] Example at https://github.com/bk2204/homedir/blob/master/.zsh/prompt_bmc_setup\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"311391","messageId":"CAP8UFD2Ve4WvyBg-DDye4Bpwb=MjB8P6V6mQdWDPbiwnVKovzg@mail.gmail.com","threadId":"45119","inReplyTo":"20170212164650.u7frv234kmu5hm7r@genre.crustytoothpaste.net","subject":"Re: Git status performance on PS (command prompt)","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2017-02-13T06:12:34Z","receivedAt":"2017-02-13T06:12:51Z","isPatch":false,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Sun, Feb 12, 2017 at 5:46 PM, brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n> On Sun, Feb 12, 2017 at 04:53:47PM +0100, Mark Gaiser wrote:\n\n[...]\n\n>> I did a bit of profiling in git to figure out where this slowdown comes from.\n>> Callgrind tells me that \"read_directory_recursive\" takes up ~62% of the time.\n>> Within that call the function \"last_exclude_matching_from_list\" takes\n>> up 49% of the time it takes to run \"git status --porcelain -b\".\n\nThe core.untrackedCache config option may help.\n"}]}