progfolio / elpaca

An elisp package manager
GNU General Public License v3.0
634 stars 31 forks source link

[Support]: Minimize elpaca memory usage #349

Closed dinkonin closed 1 month ago

dinkonin commented 1 month ago

Confirmation

Elpaca Version

Elpaca c6395a6 HEAD -> master, origin/master, origin/HEAD installer: 0.7 emacs-version: GNU Emacs 30.0.90 (build 1, aarch64-linux-gnu-gcc-8, GTK+ Version 3.24.43, cairo version 1.18.0) of 2024-08-21 git --version: git version 2.46.0

Operating System

Raspberry Pi OS

Description

I'm running emacs with elpaca on a severely memory constrained system (512 mb ram). I've noticed that after migrating to elpaca my emacs memory usage on startup has doubled with the same init.el

Any tips on optimizing this. Here's a snippet from m-x memory-report on a freshly started emacs

Estimated Emacs Memory Usage

    20 MiB  Overall Object Memory Usage
    15 MiB  Memory Used By Global Variables
   8.2 MiB  Reserved (But Unused) Object Memory
   4.5 MiB  Total Buffer Memory Usage
   2.9 MiB  Memory Used By Symbol Plists
       0 B  Total Image Cache Size

Object Storage

   9.5 MiB  Strings
   7.6 MiB  Conses
   2.1 MiB  Vectors
   931 KiB  Symbols
    14 KiB  Buffer-Objects
   9.6 KiB  Intervals
   1.1 KiB  Floats

Largest Buffers

   2.6 MiB   elpaca--read-file
   882 KiB   *code-conversion-work*
   877 KiB   *elpaca--dependencies*
   153 KiB   *elpaca--activate-package*
    25 KiB  *Async-native-compile-log*
   5.4 KiB   *code-converting-work*
   2.3 KiB  *Messages*
   2.2 KiB   *Echo Area 0*
     942 B   *Minibuf-1*
     690 B  *scratch*
     414 B  *Memory Report*
     275 B   *Minibuf-0*
     194 B   *elpaca--finalize-queue*
     194 B   *Echo Area 1*

Largest Variables

   9.1 MiB  elpaca--menu-cache
     1 MiB  elpaca--queues
   431 KiB  load-history
   424 KiB  modus-themes-faces
   220 KiB  definition-prefixes
   139 KiB  face--new-frame-defaults
   103 KiB  global-map
   103 KiB  help-quick-use-map
   103 KiB  widget-global-map
    80 KiB  coding-system-alist
    72 KiB  input-method-alist
    68 KiB  easy-menu-converted-items-table
    64 KiB  color-name-rgb-alist
    60 KiB  language-info-alist
    57 KiB  save-place-alist
    50 KiB  file-name-history

It's not a major problem for me (had emacs OOM killed just once in a week of usage) but I would appreciate some input.

progfolio commented 1 month ago

Elpaca c6395a6 HEAD -> master, origin/master, origin/HEAD installer: 0.7 emacs-version: GNU Emacs 30.0.90 (build 1, aarch64-linux-gnu-gcc-8, GTK+ Version 3.24.43, cairo version 1.18.0) of 2024-08-21 git --version: git version 2.46.0

You are running a development version of Emacs. It may be worth seeing if the issue persists on a stable version.

Any tips on optimizing this.

I can't give much advice without seeing both versions of the init files.

Do you customize any of the garbage collection settings? Have you tried running the garbage collector manually? Is this on the initial install of packages or with every Emacs session?

25 KiB  *Async-native-compile-log*

The presence of the async native compile log leads me to believe it may be the initial install.

Estimated Emacs Memory Usage

20 MiB  Overall Object Memory Usage
15 MiB  Memory Used By Global Variables

8.2 MiB Reserved (But Unused) Object Memory 4.5 MiB Total Buffer Memory Usage 2.9 MiB Memory Used By Symbol Plists 0 B Total Image Cache Size

Object Storage

9.5 MiB Strings

You could try wiping Elpaca's logs:

(cl-loop for (id . e) in (elpaca--queued)
         ;; only save latest log entry
         do (setf (elpaca<-log e) (car (elpaca<-log e))))

Largest Buffers

2.6 MiB elpaca--read-file

You can try erasing the internal buffer that is used to read in recipe caches:

(advice-add #'elpaca--read-file :after
            (lambda (&rest _) (with-current-buffer " elpaca--read-file"
                                (erase-buffer))))

877 KiB elpaca--dependencies

And the same for reading package dependency metadata:

(advice-add #'elpaca--dependencies :after
            (lambda (&rest _) (with-current-buffer " *elpaca--dependencies*"
                                (erase-buffer))))

153 KiB elpaca--activate-package 194 B elpaca--finalize-queue

Same for the above buffers as well (you can use the above advice functions as templates).

Largest Variables

9.1 MiB elpaca--menu-cache

You could also sidestep the issue of reading in the caches by skipping out on them altogether. e.g.

;; Set before Elpaca installer
(setq elpaca-menu-functions '(elpaca-menu-extensions))

Keep in mind that will require specifying parts of recipes which would normally be inherited from the menus.

Does that help?

dinkonin commented 1 month ago

You are running a development version of Emacs.

Its nearly the same on self-compiled emacs 29.4 and emacs 28.2 which unfortunately comes with the distro

Do you customize any of the garbage collection settings?

i do this in early init (setq gc-cons-threshold 128000000)

And then this in elpaca-after-init-hook (setq gc-cons-threshold 33800000)

Is this on the initial install of packages or with every Emacs session?

Nope my mistake, I just installed nerd-icons it does not show up after that

I added both advises and and the variable to my config and I do not see a difference

Largest Buffers

   2.6 MiB   elpaca--read-file
   877 KiB   *elpaca--dependencies*
   153 KiB   *code-conversion-work*
   153 KiB   *elpaca--activate-package*
   5.4 KiB   *code-converting-work*
   2.3 KiB   *Echo Area 1*
   2.3 KiB  *Messages*
     729 B   *Minibuf-1*
     673 B  *scratch*
     397 B  *Memory Report*
     258 B   *Minibuf-0*
     177 B   *elpaca--finalize-queue*
     161 B   *server*
     161 B   *Echo Area 0*

Largest Variables

   9.1 MiB  elpaca--menu-cache
     1 MiB  elpaca--queues
   813 KiB  nerd-icons/mdicon-alist
   424 KiB  modus-themes-faces
   415 KiB  load-history
   223 KiB  nerd-icons/faicon-alist
   220 KiB  definition-prefixes
   127 KiB  face--new-frame-defaults
   103 KiB  global-map
   103 KiB  help-quick-use-map
   103 KiB  widget-global-map
    80 KiB  coding-system-alist
    72 KiB  input-method-alist
    68 KiB  easy-menu-converted-items-table
    64 KiB  color-name-rgb-alist
    60 KiB  language-info-alist
    57 KiB  save-place-alist
    50 KiB  file-name-history
    50 KiB  nerd-icons/codicon-alist
    47 KiB  nerd-icons-extension-icon-alistLargest Buffers

   2.6 MiB   elpaca--read-file
   877 KiB   *elpaca--dependencies*
   153 KiB   *code-conversion-work*
   153 KiB   *elpaca--activate-package*
   5.4 KiB   *code-converting-work*
   2.3 KiB   *Echo Area 1*
   2.3 KiB  *Messages*
     729 B   *Minibuf-1*
     673 B  *scratch*
     397 B  *Memory Report*
     258 B   *Minibuf-0*
     177 B   *elpaca--finalize-queue*
     161 B   *server*
     161 B   *Echo Area 0*

Largest Variables

   9.1 MiB  elpaca--menu-cache
     1 MiB  elpaca--queues
   813 KiB  nerd-icons/mdicon-alist
   424 KiB  modus-themes-faces
   415 KiB  load-history
   223 KiB  nerd-icons/faicon-alist
   220 KiB  definition-prefixes
   127 KiB  face--new-frame-defaults
   103 KiB  global-map
   103 KiB  help-quick-use-map
   103 KiB  widget-global-map
    80 KiB  coding-system-alist
    72 KiB  input-method-alist
    68 KiB  easy-menu-converted-items-table
    64 KiB  color-name-rgb-alist
    60 KiB  language-info-alist
    57 KiB  save-place-alist
    50 KiB  file-name-history
    50 KiB  nerd-icons/codicon-alist
    47 KiB  nerd-icons-extension-icon-alist

I don't want to waste any more of your time as I realize this is a very niche issue, so I think I'll just make another config for my raspberry use case, and install packages with package.el in it. I'll continue to use the awesome elpaca everywhere else, thank you @progfolio !