Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[low prio] [feature inquiry] GCMH: Garbage Collector Magic Hack: suitable for Spacemacs? #16145

Open
stradicat opened this issue Sep 17, 2023 · 3 comments

Comments

@stradicat
Copy link
Contributor

I recently found out about Andrea Corallo's Garbage Collector Magic Hack (gcmh), which changes GC thresholds at load time and after finished loading Emacs, to allow for quicker startup and shortening GC pauses:
https://akrl.sdf.org

However, as memory usage goes with Spacemacs and multiple layers, I wanted to ask if you think it's worth adding as a feature or layer.

@BenedictHW
Copy link
Contributor

Emacs maintainer Eli Zaretskii has useful information on a default value if its to be included in Spacemacs.
https://old.reddit.com/r/emacs/comments/bg85qm/garbage_collector_magic_hack/

Personally what made the biggest difference for me for spacemacs performance is

  1. Use the emacs profiler. Spacemacs binds this to =SPC h P=

Setting =savehist-autosave-interval= to 60 seconds (from the default of 300) and
=history-length= to 1000 (from the default of 100) uses a lot of processing
power. Performance problems can be plainly seen by using the Emacs cpu+mem
profiler. See
https://emacs.stackexchange.com/questions/12086/high-cpu-memory-usage-and-abnormally-large-savehist-file
=spacemacs-defaults/init-savehist=, Spacemacs Github issues #9409, #1369.

Here's my config for savehist,

  (setf history-length 25
        savehist-save-minibuffer-history nil
        savehist-autosave-interval nil
        kill-ring-max 200
        savehist-mode nil)
  (delq 'mark-ring savehist-additional-variables)
  (delq 'global-mark-ring savehist-additional-variables)
  (delq 'search-ring savehist-additional-variables)
  (delq 'regexp-search-ring savehist-additional-variables)
  (delq 'extended-command-history savehist-additional-variables)
  (delq 'kill-ring savehist-additional-variables)
  (put 'org-brain-headline-cache 'history-length 10)
  (put 'bibtex-completion-cache 'history-length 10)
  (push 'org-brain-headline-cache savehist-additional-variables)
  (push 'bibtex-completion-cache savehist-additional-variables)
  (push 'helm-ff-history savehist-additional-variables)
  (push 'org-clock-history savehist-additional-variables)
  ;; Emacs profiler shows `savehist-autosave' is very performance intensive.
  (add-hook 'kill-emacs-hook #'savehist-save) ; Savehist only on exit.
  1. Comment out packages I don't need. The following is from the layers section in my .spacemacs
   ;; I prefer no battery info on my modeline. Emacs profiler tells me the
   ;; package uses a lot of battery itself.
   ;; Ditto for icons, lots of wasted cpu cycles for no functionality.
   ;; Symon is cute, but https://github.com/zk-phi/symon/issues/42 shows
   ;; that a significant performance price is paid.
   (spacemacs-modeline :packages (not
                                  anzu
                                  fancy-battery
                                  font-lock+
                                  neotree
                                  ;; spaceline-all-the-icons
                                  symon
                                  vim-powerline))
   (spacemacs-navigation :packages (not
                                    restart-emacs
                                    ;; `avy-goto-word-or-subword-1' is a more general use case.
                                    ace-link
                                    ;; I believe the winum (SPC 1) and avy-word (jumps across windows)
                                    ;; is enough.
                                    ace-window
                                    ;; package-list-packages and
                                    ;; package-menu-filter-by-keyword "status:installed"
                                    ;; paradox
                                    ;; More gimmicky than useful.
                                    golden-ratio
                                    ;; Utility packages that I have no use for.
                                    centered-cursor-mode
                                    open-junk-file
                                    auto-highlight-symbol))

A lot of low hanging fruit in my opinion. Definitely a system-specific setting. I would help test a PR.

@stradicat
Copy link
Contributor Author

Thanks for the detailed suggestion!

I found this comment on the Doom Emacs repo yesterday, with some insights on the matter by Henrik Lissner: doomemacs/doomemacs#3108

Still, I'm going to test the profiler on x86_64 Linux + macOS & i686 Linux, then come back with results.

@sunlin7
Copy link
Contributor

sunlin7 commented Apr 28, 2024

Actually Spacemacs already do that.
At begin of startup, the gc parameters were gc-cons-threshold 402653184 gc-cons-percentage 0.6, or (400M, 0.6).
At the end of startup, the gc parameters will change to customer ones, default is (100M, 0.1).
https://github.com/syl20bnr/spacemacs/blob/develop/init.el#L31
https://github.com/syl20bnr/spacemacs/blob/develop/core/core-spacemacs.el#L266-L267

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants