TIL Speed up Magit on MacOS

1 min read

I’ve been using Magit in Emacs for many years and on larger (and some smaller) projects there would usually be a 3 to 5 second delay with magit-status and commits. Today I’ve been refactoring my config and fixing annoyances and learned that setting the git executable explicitly fixed that issue for me - from about 4 seconds down to less than a second.

(use-package magit
  :bind ("C-x g" . magit-status)
  :custom
  (magit-git-executable "/opt/homebrew/bin/git"))

Comments from Mastodon

21 comments • Join the discussion

Arch 💕's avatar
Arch 💕 @archenoth@chitter.xyz
View on Mastodon

@greg so, turns out there's an little extra detail in here! mac already has a git binary at /usr/bin/git!

but if you `brew install git`, and then set the magit git path to the brew version explicitly--it seems like the *newer version* brew pulls in is where the real speed gain happens!

but yeah! that speedup is drastic, damn

Arch 💕's avatar
Arch 💕 @archenoth@chitter.xyz
View on Mastodon

@greg hm! maybe!

for me, it looked like if i didn't specify that custom variable directly, magit would actually totally bypass exec-path-from-shell, though!

(since the default value for that variable was "/usr/bin/git", which does exist, meaning it didn't need to hunt on $PATH)

tl;dr - magit seems to prioritize explicitly using any version that lives in /usr/bin/, even if $PATH would resolve elsewhere

1
Arch 💕's avatar
Arch 💕 @archenoth@chitter.xyz
View on Mastodon

@greg i'm learning things! ahaha

(also, i just noticed you have fedi comments as blog comments! that kinda rules! :kirby_happy:)

1
Greg Newman's avatar
Greg Newman @greg
View on Mastodon

@archenoth me too! Always learning. thanks. I wrote that code this week. I have to hook up a cron on cloudflare to grab the latest comments. And also need to make it threaded.

1
Arch 💕's avatar
Arch 💕 @archenoth@chitter.xyz
View on Mastodon

@greg oh yeah! threading is tricky! (i wrote a simple client-side version of this earlier for my blog too, and haven't done that part either! ahah)

though, user icons are pretty easy to implement if you wanted to build something easier before doing that! since the uri just lives in account.avatar

(like this! github.com/Archenoth/archenoth)

custom emoji can also be directly pulled out of comments and replaced with image tags using global regex too! (like this! github.com/Archenoth/archenoth)

Arch 💕's avatar
Arch 💕 @archenoth@chitter.xyz
View on Mastodon

@greg but also, the fact you can do something like this *at all* feels so nice!

i love the fediverse, aaa

1
Greg Newman's avatar
Greg Newman @greg
View on Mastodon

@archenoth cool I’ll check this out. Thanks! I’m already grabbing avatars at this point. I just need to look a little deeper at the json response for deeper replies.

1
Greg Newman's avatar
Greg Newman @greg
View on Mastodon

@archenoth good find and great info! There is a verbose setting for magit to output everything to messages to find bottlenecks but I didn’t have to go that far.

1
Steve Purcell's avatar
Steve Purcell @sanityinc@hachyderm.io
View on Mastodon

@greg @archenoth fwiw, exec-path-from-shell shouldn't slow anything down. It runs once at startup and sets exec-path. Only if you had thousands of non-git-containing directories in your path might that get slow. So the speed difference is almost certainly down to the specific git found. If anything, exec-path-from-shell should help Emacs find the homebrew git you'd typically be using in a terminal.

Greg Newman's avatar
Greg Newman @greg
View on Mastodon

@sanityinc @archenoth magit-version tells me `Magit v4.1.2-3-g1c30bb1f, Transient 0.7.9, Git 2.50.1, Emacs 30.2, darwin` which i know by 2.50.1 that is my homebrew version. the Apple version is 2.39.5

1
Steve Purcell's avatar
Steve Purcell @sanityinc@hachyderm.io
View on Mastodon

@greg @archenoth For me, the bigger question would be why the homebrew version isn't earlier in your $PATH / exec-path. You shouldn't normally have to go around setting vars to point at specific executables.

David's avatar
David @idcrook@mastodon.social
View on Mastodon

@greg don't know if this would work more robustly across systems (are there still Intel Macs in use out there? 😆 ) but I added this in my straight.el-based startup in (use-package magit :config ....

;; adapted from gregnewman.io/blog/speed-up-ma
(let ((git (executable-find "git")))
(when git (setq magit-git-executable git)))

Álvaro R.'s avatar
Álvaro R. @xenodium@indieweb.social
View on Mastodon

@greg @idcrook I also needed “brew install git” since I was using git from system which is likely quite old. If using executable-find, check the resulting path (and exec-path).