Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51515ad

Browse files
authored
Merge pull request #187 from pzelnip/ps1isslow
Speeding up my bash prompt post
2 parents 5a218b3 + a37cd4c commit 51515ad

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

content/slow-bash-prompt.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Title: Fixing a Slow Bash Prompt
2+
Date: 2021-02-01 16:49
3+
Modified: 2021-02-01 16:49
4+
Category: Posts
5+
tags: bash,git,osx,homebrew
6+
cover: static/imgs/default_page_imagev2.jpg
7+
summary: My bash prompt seemed to be slow. Here's how I fixed it
8+
9+
I recently got a new machine for my new job, and so I'm going through all the
10+
"new machine setup" gotchas. Since getting it, I've been finding the
11+
shell/terminal has felt really sluggish. Like I’d hit enter in a terminal and
12+
it’d be 1-2 seconds before the prompt came back allowing me to type anything
13+
again, which makes someone who likes to type a lot of commands in quick
14+
succession get angry. 😠
15+
16+
After a bunch of troubleshooting & reverse engineering I found it came down to
17+
the `__git_ps1` function that displays your current branch in your bash prompt.
18+
How slow was it? Really slow:
19+
20+
``` shell
21+
λ time __git_ps1
22+
(mainline)
23+
real 0m1.746s
24+
user 0m0.044s
25+
sys 0m0.079s
26+
```
27+
28+
That’s 1.7 seconds every time I hit enter in a terminal because it gets
29+
evaluated as part of producing my bash prompt.
30+
31+
I thought this was weird, so I did a `git --version` and noticed that I was
32+
running `git version 2.24.3 (Apple Git-128)`. That is the special “Apple has
33+
built this version for you and installed as part of Xcode command-line tools”
34+
version.
35+
36+
So, I installed git from Homebrew (`brew install git`), which gave be the same
37+
normal version that anyone on any platform would get (just compiled for OSX),
38+
and also gave me a much newer version (2.30.0). Much faster. How much faster?
39+
Check it out:
40+
41+
```shell
42+
λ time __git_ps1
43+
(mainline)
44+
real 0m0.060s
45+
user 0m0.016s
46+
sys 0m0.026s
47+
```
48+
49+
From 1.7 seconds to 0.06 seconds. Crazy. Now my command prompt is nice and
50+
snappy.

0 commit comments

Comments
 (0)