Fork me on GitHub
#spacemacs
<
2022-02-22
>
jumar09:02:49

I've been quite annoyed by magit's slowness in the past few months. I'm not sure when it started happening but I typically have to wait about 5 seconds for things like magit-status or even commit. It definitely used to be much faster (perhaps 2 seconds, but not 5+) As an experiment, I changed magit-diff-refine-hunk variable to t (selected) and then to never - it's perhaps a bit faster but still slow. Here's the cpu profile I tried to capture:

- magit-status-refresh-buffer                             449  55%
         - magit-run-section-hook                                 433  53%
          - apply                                                 433  53%
           + magit-insert-status-headers                          129  16%
           + magit-insert-unpushed-to-pushremote                   78   9%
           + magit-insert-stashes                                  69   8%
           + magit-insert-unpushed-to-upstream-or-recent                 36   4%
           + magit-insert-staged-changes                           26   3%
           + magit-insert-untracked-files                          25   3%
           + magit-insert-unstaged-changes                         24   2%
           + forge-insert-pullreqs                                 17   2%
           + magit-insert-unpulled-from-pushremote                 12   1%
           + magit-insert-merge-log                                11   1%
           + magit-insert-rebase-sequence                           1   0%
           + magit-insert-sequencer-sequence                        1   0%
           + magit-insert-bisect-log                                1   0%

jumar09:02:04

What is your experience when using magit? Is it typically fast enough?

jumar09:02:53

Even just stashing changes takes at least 2 seconds. Commit takes at least 3 seconds (even with magit-diff-refine-hunk set to never)

practicalli-johnny09:02:26

I haven't noticed any speed problems in general. There are some slow cases when committing changes in a large JSON file • figwheel-main build for GitHub pages • really long config file for VSpaceCode I assume this slow down is due to font locking the diffs. I can run the profiler next time I use magit and share the numbers I get

jumar09:02:26

Perfect, thanks -it's really painful for me - even for very small diffs

jumar09:02:07

How fast are typical operations like status, stash, commit for you?

practicalli-johnny09:02:24

No noticeable slowdown except for the JSON cases mentioned before. The only time I recall magit being slow was when Spacemacs included Magithub, but that seems like a long time ago. magit forge doesn't seem to affect performance, although downloading issues can take a second or so when manually invoking an issue update I think I have these variables set https://practical.li/spacemacs/source-control/forge-configuration.html#configure-the-number-of-open-and-closed-topics-shown-in-forge

jumar09:02:47

Ok, thanks. When you say "no noticable slowdown" what does that mean? Does status, stash, commit and similar operations complete within a second? two seconds? more?

jumar09:02:54

Btw. it's somewhat faster after I upgraded emacs (just tiny version upgrade) and all the packages. I also kept magit-diff-refine-hunk var set to t (selected).

practicalli-johnny10:02:13

All magit actions happen pretty much instantaneously, no noticeable delay (so much less than a second). I ran the Emacs profiler and magit status hit about 20% cpu briefly. In the time it took to refresh the profile report it was back to 0%

practicalli-johnny10:02:05

My spacemacs git layer configuration is

(git :variables
          git-magit-status-fullscreen t
          magit-diff-refine-hunk t
          git-enable-magit-todos-plugin t)

practicalli-johnny10:02:05

In .spacemacs dotspacemacs/user-config I have the following to ensure closed issues are not included for magit forge. But this should only be an issue when pulling issue uptates, @ f f in magit status.

(setq  forge-topic-list-limit '(100 . -10))

practicalli-johnny10:02:40

I have git version 2.23.0 installed (2.35.1 is the latest available), so fairly recent. Magit emacs package is magit-20220203.2302 , so I must have updated after 3rd of February 2020

practicalli-johnny10:02:19

Another aspect could be the Clojure project itself, especially if its a very very large project. If the slowness is happening on all projects then its probably some Emacs / magit issue

jumar13:02:27

I've just tried on a smaller project (https://github.com/jumarko/clojure-experiments/) and it's faster - but still far from "instanteneous"; perhaps 1.5-2 seconds

jumar14:02:31

I studied a few resources, notably https://jakemccrary.com/blog/2020/11/14/speeding-up-magit, and learned about magit-refresh-verbose After implementing the suggestion the time went down from 2.5 seconds to less than a second! Before:

Refreshing buffer 'magit: codescene'...
  magit-insert-error-header                          9.9e-05 
  magit-insert-diff-filter-header                    0.033033 !!
  magit-insert-head-branch-header                    0.097403 !!
  magit-insert-upstream-branch-header                0.000375 
  magit-insert-push-branch-header                    0.066162 !!
  magit-insert-tags-header                           0.459343 !!
  magit-insert-status-headers                        0.70068 !!
  magit-insert-merge-log                             0.028536 !
  magit-insert-rebase-sequence                       0.000688 
  magit-insert-am-sequence                           0.000169 
  magit-insert-sequencer-sequence                    0.000325 
  magit-insert-bisect-output                         0.000172 
  magit-insert-bisect-rest                           4.4e-05 
  magit-insert-bisect-log                            4.5e-05 
  magit-insert-untracked-files                       0.887013 !!
  magit-insert-unstaged-changes                      0.119067 !!
  magit-insert-staged-changes                        0.068917 !!
  magit-insert-stashes                               0.145984 !!
  magit-insert-unpushed-to-pushremote                0.166327 !!
  magit-insert-unpushed-to-upstream-or-recent        0.112718 !!
  magit-insert-unpulled-from-pushremote              0.084049 !!
  magit-insert-unpulled-from-upstream                3e-06 
  forge-insert-pullreqs                              0.049881 !!
  forge-insert-issues                                9e-06 
Refreshing buffer 'magit: codescene'...done (2.482s)
AFTER:
Refreshing buffer 'magit: codescene'...
  magit-insert-merge-log                             0.032955 !!
  magit-insert-rebase-sequence                       0.000745 
  magit-insert-am-sequence                           0.000161 
  magit-insert-sequencer-sequence                    0.001377 
  magit-insert-bisect-output                         0.000163 
  magit-insert-bisect-rest                           5.1e-05 
  magit-insert-bisect-log                            4.4e-05 
  magit-insert-untracked-files                       0.407428 !!
  magit-insert-unstaged-changes                      0.121312 !!
  magit-insert-staged-changes                        0.073821 !!
  magit-insert-stashes                               0.147271 !!
  forge-insert-pullreqs                              0.039658 !!
  forge-insert-issues                                5e-06 
Refreshing buffer 'magit: codescene'...done (0.908s)

jumar14:02:48

This was also helpful: https://magit.vc/manual/magit/Performance.html#Committing-Performance-1

(remove-hook 'server-switch-hook 'magit-commit-diff)