Doom-emacs: [HOWTO] Speed up org-agenda

Created on 5 Mar 2020  路  9Comments  路  Source: hlissner/doom-emacs

What are you trying to achieve?
The loading of the org-agenda is very slow compared to vanilla Emacs (and my previous config), what can I do to speed it up?

What have you tried?
Just measurements, since this is beyond my knowledge.

Additional information

  • I have almost 200 org files that are 6.8 MB in size.
  • My old, quite extensive Emacs config, loads my org-agenda in under 10 s initially, then in under 1 s subsequently.
  • Doom Emacs loads my org-agenda in about 20 s initially, then in about 2 s subsequently.

System information

emacs   version    26.3
        features   XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GLIB NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS LUCID X11 XDBE XIM MODULES THREADS LIBSYSTEMD LCMS2
        build      sep 20, 2019
        buildopts  (--prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib --localstatedir=/var --with-x-toolkit=lucid --with-xft --without-gconf --without-gsettings --with-modules '--program-transform-name=s/^ctags$/ctags.emacs/' 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt' CPPFLAGS=-D_FORTIFY_SOURCE=2 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now)
        windowsys  x
        daemonp    daemon
doom    version    2.0.9
        build      HEAD -> develop, origin/develop, origin/HEAD ed2fb6836 2020-03-03 23:33:53 -0500
        dir        ~/.doom.d/
system  type       gnu/linux
        config     x86_64-pc-linux-gnu
        shell      /bin/bash
        uname      Linux 5.4.23-1-MANJARO #1 SMP PREEMPT Fri Feb 28 22:45:29 UTC 2020 x86_64
        path       (~/.local/bin ~/.emacs.d/bin ~/.local/bin /bin /usr/bin /usr/local/bin /usr/local/sbin /usr/lib/jvm/default/bin /usr/bin/site_perl /usr/bin/vendor_perl /usr/bin/core_perl /usr/lib/emacs/26.3/x86_64-pc-linux-gnu/)
config  envfile    envvar-file
        elc-files  0
        modules    (:completion company ivy :ui doom doom-dashboard doom-quit hl-todo indent-guides modeline nav-flash ophints (popup +defaults) vc-gutter vi-tilde-fringe window-select workspaces :editor (evil +everywhere) file-templates fold snippets :emacs dired electric vc :checkers syntax :tools (eval +overlay) lookup magit :lang data emacs-lisp markdown (org +dragndrop +present) sh :config (default +bindings +smartparens))
        packages   (n/a)
        unpin      (n/a)
        elpa       (n/a)
((emacs
  (version . "26.3")
  (features . "XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GLIB NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS LUCID X11 XDBE XIM MODULES THREADS LIBSYSTEMD LCMS2")
  (build . "sep 20, 2019")
  (buildopts "--prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib --localstatedir=/var --with-x-toolkit=lucid --with-xft --without-gconf --without-gsettings --with-modules '--program-transform-name=s/^ctags$/ctags.emacs/' 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt' CPPFLAGS=-D_FORTIFY_SOURCE=2 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now")
  (windowsys . batch)
  (daemonp . server-running))
 (doom
  (version . "2.0.9")
  (build . "HEAD -> develop, origin/develop, origin/HEAD ed2fb6836 2020-03-03 23:33:53 -0500")
  (dir . "~/.doom.d/"))
 (system
  (type . gnu/linux)
  (config . "x86_64-pc-linux-gnu")
  (shell . "/bin/bash")
  (uname . "Linux 5.4.23-1-MANJARO #1 SMP PREEMPT Fri Feb 28 22:45:29 UTC 2020 x86_64")
  (path "~/.local/bin" "~/.emacs.d/bin" "~/.local/bin" "/bin" "/usr/bin" "/usr/local/bin" "/usr/local/sbin" "/usr/lib/jvm/default/bin" "/usr/bin/site_perl" "/usr/bin/vendor_perl" "/usr/bin/core_perl" "/usr/lib/emacs/26.3/x86_64-pc-linux-gnu"))
 (config
  (envfile . envvar-file)
  (elc-files . 0)
  (modules :completion company ivy :ui doom doom-dashboard doom-quit hl-todo indent-guides modeline nav-flash ophints (popup +defaults) vc-gutter vi-tilde-fringe window-select workspaces :editor (evil +everywhere) file-templates fold snippets :emacs dired electric vc :checkers syntax :tools (eval +overlay) lookup magit :lang data emacs-lisp markdown (org +dragndrop +present) sh :config (default +bindings +smartparens))
  (packages "n/a")
  (unpin "n/a")
  (elpa "n/a")))

:lang org bug performance resolved

Most helpful comment

As of e86ecf6 and 4209454 that optimization (and two more) are now in our lang/org module. The two extra optimizations should reduce how much time org-agenda spends in doom--optimize-for-large-files-a. More testing needs to be done to ensure no side-effects arise from these fixes, but for now I'll consider this resolved. Let me know if performances issues arise again and I'll reopen this.

Thanks for bringing it to my attention!

All 9 comments

Profiler output with the relevant calls expanded:

- command-execute                                                                             16526  95%
 - call-interactively                                                                         16526  95%
  - funcall-interactively                                                                     16526  95%
   - klorax/agenda                                                                            16249  94%
    - org-agenda                                                                              16249  94%
     - org-let                                                                                16249  94%
      - eval                                                                                  16249  94%
       - let                                                                                  16249  94%
        - org-agenda-list                                                                     16249  94%
         - org-agenda-prepare                                                                 15387  89%
          - org-agenda-prepare-buffers                                                        15290  88%
           - org-get-agenda-file-buffer                                                       15072  87%
            - apply                                                                           15072  87%
             - +org--exclude-agenda-buffers-from-recentf-a                                    15072  87%
              - let                                                                           15072  87%
               - funcall                                                                      15072  87%
                - #<compiled 0x2165595>                                                       15072  87%
                 - find-file-noselect                                                         14305  82%
                  - find-file-noselect-1                                                      13638  79%
                   - after-find-file                                                          13544  78%
                    - apply                                                                   13544  78%
                     - doom--optimize-for-large-files-a                                       13062  75%
                      - if                                                                    13062  75%
                       - apply                                                                12813  74%
                        - #<compiled 0x1b4687>                                                12813  74%
                         - normal-mode                                                         6536  37%
                          - set-auto-mode                                                      6104  35%
                           - apply                                                             6104  35%
                            - #<compiled 0x23be0bd>                                            6102  35%
                             - apply                                                           6102  35%
                              - so-long--set-auto-mode                                         6100  35%
                               - apply                                                         6088  35%
                                - #<compiled 0x1b4e63>                                         6088  35%
                                 - set-auto-mode-0                                             6057  35%
                                  - org-mode                                                   6057  35%
                                   - org-install-agenda-files-menu                             4316  25%
                                    - org-agenda-files                                         4270  24%
                                     - mapcar                                                  4270  24%
                                        #<compiled 0x2163681>                                  4135  23%
                                        #<compiled 0x2163691>                                   126   0%
                                    + easy-menu-change                                           46   0%
                                   + org-update-radio-target-regexp                            1069   6%
                                   + run-mode-hooks                                             487   2%
                                   + org-macro-initialize-templates                              84   0%
                                   + org-set-regexps-and-options                                 41   0%
                                   + outline-mode                                                41   0%
                                   + set-face-foreground                                          7   0%
                                   + org-find-invisible-foreground                                3   0%
                                 + hack-local-variables                                          13   0%
                                   assoc-default                                                 10   0%
                                   inhibit-local-variables-p                                      4   0%
                                   set-auto-mode-1                                                2   0%
                               + so-long--check-header-modes                                     10   0%
                            + auto-minor-mode-set                                                 2   0%
                          + run-hooks                                                           429   2%
                            kill-all-local-variables                                              3   0%
                         - run-hooks                                                           6264  36%
                          - save-place-find-file-hook                                          3861  22%
                           - apply                                                             3861  22%
                            - #<compiled 0x29698f5>                                            3861  22%
                             - apply                                                           3861  22%
                              - ad-Advice-save-place-find-file-hook                            3861  22%
                               - #<compiled 0x296b8f5>                                         3861  22%
                                - apply                                                        3861  22%
                                 - +nav-flash-blink-cursor-a                                   3861  22%
                                  - if                                                         3861  22%
                                   - +nav-flash-blink-cursor                                   3861  22%
                                    - if                                                       3861  22%
                                     - nav-flash-show                                          3861  22%
                                      - beginning-of-visual-line                               2923  16%
                                       - vertical-motion                                       2857  16%
                                        - jit-lock-function                                    2857  16%
                                         - jit-lock-fontify-now                                2853  16%
                                          - jit-lock--run-functions                            2853  16%
                                           - run-hook-wrapped                                  2853  16%
                                            - #<compiled 0x2583b29>                            2853  16%
                                             - highlight-indent-guides--guide-region           1523   8%
                                              - font-lock-fontify-region                       1435   8%
                                               - font-lock-default-fontify-region              1435   8%
                                                - font-lock-fontify-keywords-region            1425   8%
                                                   org-do-latex-and-related                     984   5%
                                                 + org-fontify-meta-lines-and-blocks            290   1%
                                                   org-font-lock-add-priority-faces              49   0%
                                                 + org-activate-links                            26   0%
                                                 + org-do-emphasis-faces                         13   0%
                                                   org-activate-dates                             3   0%
                                                 + org-activate-footnote-links                    3   0%
                                                + font-lock-unfontify-region                      4   0%
                                                syntax-ppss                                      36   0%
                                              + highlight-indent-guides--get-prev-guides         14   0%
                                                highlight-indent-guides--calc-guides              3   0%
                                             + font-lock-fontify-region                        1310   7%
                                             + goto-address-fontify-region                       20   0%
                                      + end-of-visual-line                                      932   5%
                                      + nav-flash-use-pulse-p                                     3   0%
                                      + run-at-time                                               3   0%
                          + projectile-find-file-hook-function                                 1201   6%
                          + doom-modeline-update-buffer-file-name                               468   2%
                          + vc-refresh-state                                                    339   1%
                          + +vc-gutter-init-maybe-h                                             279   1%
                          + undo-tree-load-history-from-hook                                     68   0%
                          + recentf-track-opened-file                                            32   0%
                          + whitespace-turn-on-if-enabled                                         3   0%
                          + global-undo-tree-mode-check-buffers                                   3   0%
                            global-flycheck-mode-check-buffers                                    2   0%
                            global-evil-surround-mode-check-buffers                               2   0%
                           make-auto-save-file-name                                               3   0%
                       + prog1                                                                  249   1%
                     + #<compiled 0x19b9911>                                                    482   2%
                   + insert-file-contents                                                        23   0%
                   + file-truename                                                               16   0%
                  + find-buffer-visiting                                                         53   0%
                  + file-truename                                                                18   0%
                    abbreviate-file-name                                                         10   0%
                  + create-file-buffer                                                            6   0%
                 + org-find-base-buffer-visiting                                                767   4%
             org-refresh-category-properties                                                     62   0%
           + org-refresh-effort-properties                                                       30   0%
             org-refresh-stats-properties                                                        30   0%
             org-refresh-properties                                                              24   0%
           + org-set-regexps-and-options                                                         24   0%
          + org-agenda-mode                                                                      77   0%
          + org-agenda-files                                                                     17   0%
         + apply                                                                                568   3%
         + org-agenda-finalize                                                                  167   0%
         + org-agenda-finalize-entries                                                           40   0%
         + org-agenda-files                                                                      20   0%
         + org-days-to-iso-week                                                                  10   0%
           org-check-agenda-file                                                                  3   0%
           org-agenda-add-time-grid-maybe                                                         3   0%
           ws-butler-after-change                                                                 3   0%
   + counsel-M-x                                                                                247   1%
   + handle-focus-in                                                                             30   0%
+ ...                                                                                           537   3%
+ timer-event-handler                                                                           183   1%
+ redisplay_internal (C function)                                                                 6   0%

Where klorax/agenda is just:

  (defun klorax/agenda (&optional arg)
    (interactive "P")
    (org-agenda arg "A"))

Not sure whether this helps but in my case setting org-agenda-dim-blocked-tasks to nil gave me a few seconds (I think) and before I used doom I didn't use that option anyway. It seems to default to non-nil in doom, making stuff slow(er). See also https://orgmode.org/org.html#Speeding-Up-Your-Agendas .

Would (setq org-agenda-inhibit-startup t) help? This prevents org-mode from running all kinds of startup work (like handling visibility, realigning tables, etc) while org-agenda is loading them in the background.

Hey, thank your for addressing this :slightly_smiling_face: At least for me, #2672 does not improve the load time of the agenda noticeably, though.

@dpaetzel @klorax If you are still experiencing this slowness, could one of you try adding this to ~/.doom.d/config.el and let me know if it improves the situation?

(defadvice! fix-exclude-agenda-buffers-from-recentf-advice (orig-fn file)
  :override #'+org--exclude-agenda-buffers-from-recentf-a
  (let ((recentf-exclude (list (lambda (_file) t)))
        find-file-hook)
    (funcall orig-fn file)))

Thanks a lot! I performed two measurements (after upgrading doom to the latest version, each done with a freshly started Emacs, each with the options recommended earlier in this thread).

  1. With the defadvice the agenda takes approximately 29 seconds to load. Subsequent calls (without restarting Emacs) take around 2-3 seconds.
  2. Without the defadvice the agenda takes approximately 44 seconds to load. Subsequent calls (without restarting Emacs) take around 3 seconds.

It looks like the defadvice gives me a speed boost of around 30% which is great :slightly_smiling_face: Nevertheless there still seems something to be going on because I do not think that I had to wait for 30 seconds for the agenda to start before I used doom.

Thanks for looking into this, been using my vanilla config so took a little while to test your change.

Profiler Output

Below is profiler output, for Doom respectively Vanilla, and the ratio between those is 3174 / 2710 ~ 17 % time increase (down from something like 100 %).

Doom Profiler Output

- command-execute                                                                              3174  89%
 - call-interactively                                                                          3174  89%
  - funcall-interactively                                                                      3174  89%
   - klorax/agenda                                                                             3105  87%
    - org-agenda                                                                               3105  87%
     - org-let                                                                                 3105  87%
      - eval                                                                                   3105  87%
       - let                                                                                   3105  87%
        - org-agenda-list                                                                      3105  87%
         - org-agenda-prepare                                                                  2894  81%
          - org-agenda-prepare-buffers                                                         2874  80%
           - org-get-agenda-file-buffer                                                        2807  78%
            - apply                                                                            2807  78%
             - +org--exclude-agenda-buffers-from-recentf-a                                     2807  78%
              - apply                                                                          2807  78%
               - fix-exclude-agenda-buffers-from-recentf-advice                                2807  78%
                - let                                                                          2807  78%
                 - funcall                                                                     2807  78%
                  - #<compiled 0x1570851035d5>                                                 2807  78%
                   - find-file-noselect                                                        2621  73%
                    - find-file-noselect-1                                                     2439  68%
                     - after-find-file                                                         2407  67%
                      - apply                                                                  2407  67%
                       - #<compiled 0x1570846549a5>                                            2407  67%
                        - apply                                                                2407  67%
                         - #<compiled 0x157083e0cc51>                                          2400  67%
                          - apply                                                              2400  67%
                           - doom--optimize-for-large-files-a                                  2400  67%
                            - if                                                               2400  67%
                             - apply                                                           2329  65%
                              - #<compiled 0x1ffd052f655f>                                     2329  65%
                               - normal-mode                                                   2320  65%
                                - set-auto-mode                                                2270  63%
                                 - apply                                                       2270  63%
                                  - #<compiled 0x157084744329>                                 2144  60%
                                   - apply                                                     2144  60%
                                    - so-long--set-auto-mode                                   2144  60%
                                     - apply                                                   2140  60%
                                      - #<compiled 0x1ffd052d4179>                             2139  60%
                                       - set-auto-mode-0                                       2129  59%
                                        - org-mode                                             2129  59%
                                         - org-install-agenda-files-menu                       1296  36%
                                          - org-agenda-files                                   1288  36%
                                           - mapcar                                            1287  36%
                                              #<compiled 0x157085103255>                       1190  33%
                                              #<compiled 0x157085103395>                         96   2%
                                          + easy-menu-change                                      7   0%
                                          + mapcar                                                1   0%
                                         + run-mode-hooks                                       433  12%
                                         + org-update-radio-target-regexp                       333   9%
                                         + org-macro-initialize-templates                        20   0%
                                         + org-set-regexps-and-options                           15   0%
                                         + outline-mode                                          14   0%
                                         + use-local-map                                         10   0%
                                         + org-find-invisible-foreground                          3   0%
                                       + hack-local-variables                                     4   0%
                                         assoc-default                                            3   0%
                                         inhibit-local-variables-p                                1   0%
                                       + set-auto-mode-1                                          1   0%
                                     + so-long--check-header-modes                                4   0%
                                  + so-long--set-auto-mode                                      124   3%
                                  + auto-minor-mode-set                                           2   0%
                                + run-hooks                                                      49   1%
                                  font-lock-mode                                                  1   0%
                               + run-hooks                                                        5   0%
                             + prog1                                                             69   1%
                             + setq                                                               2   0%
                         + doom-first-file-hook-h                                                 7   0%
                     + file-truename                                                              7   0%
                     + insert-file-contents                                                       7   0%
                       abbreviate-file-name                                                       2   0%
                    + file-truename                                                              21   0%
                    + find-buffer-visiting                                                       11   0%
                      abbreviate-file-name                                                        3   0%
                    + create-file-buffer                                                          3   0%
                   + org-find-base-buffer-visiting                                              186   5%
           + org-refresh-category-properties                                                     23   0%
           + org-refresh-effort-properties                                                        8   0%
             org-refresh-properties                                                               8   0%
           + org-set-regexps-and-options                                                          7   0%
             org-refresh-stats-properties                                                         7   0%
           + org-in-commented-heading-p                                                           1   0%
             org-end-of-subtree                                                                   1   0%
          + org-agenda-mode                                                                      14   0%
          + org-agenda-files                                                                      6   0%
         + apply                                                                                154   4%
         + org-agenda-finalize                                                                   21   0%
         + org-agenda-finalize-entries                                                           12   0%
         + org-agenda-files                                                                       6   0%
         + org-days-to-iso-week                                                                   4   0%
           org-check-agenda-file                                                                  2   0%
           put-text-property                                                                      1   0%
   + counsel-M-x                                                                                 68   1%
   + org-agenda-quit                                                                              1   0%
+ ...                                                                                           328   9%
+ timer-event-handler                                                                            57   1%

Vanilla Profiler Output

- command-execute                                                2710  74%
 - call-interactively                                            2710  74%
  - funcall-interactively                                        2710  74%
   - klorax/agenda                                               2532  69%
    - org-agenda                                                 2532  69%
     - org-let                                                   2532  69%
      - eval                                                     2532  69%
       - let                                                     2532  69%
        - org-agenda-list                                        2532  69%
         - org-agenda-prepare                                    2419  66%
          - org-agenda-prepare-buffers                           2411  66%
           - org-get-agenda-file-buffer                          2337  64%
            - find-file-noselect                                 2229  61%
             - find-file-noselect-1                              2094  57%
              - after-find-file                                  2060  56%
               - normal-mode                                     1728  47%
                - set-auto-mode                                  1669  45%
                 - set-auto-mode-0                               1657  45%
                  - org-mode                                     1657  45%
                   - org-install-agenda-files-menu                976  26%
                    - org-agenda-files                            967  26%
                     - mapcar                                     966  26%
                      - #<compiled 0x15681e0ae305>                965  26%
                         directory-files                            1   0%
                    + easy-menu-change                              8   0%
                      mapcar                                        1   0%
                   + org-update-radio-target-regexp               346   9%
                   + org-set-startup-visibility                   126   3%
                   + run-mode-hooks                               107   2%
                   + org-macro-initialize-templates                54   1%
                   + org-set-regexps-and-options                   23   0%
                   + outline-mode                                   8   0%
                   + org-set-font-lock-defaults                     5   0%
                   + use-local-map                                  5   0%
                   + org-find-invisible-foreground                  3   0%
                   + set-face-foreground                            1   0%
                 + hack-local-variables                             6   0%
                   assoc-default                                    3   0%
                 + inhibit-local-variables-p                        2   0%
                 + set-auto-mode-1                                  1   0%
                + run-hooks                                        48   1%
                + kill-all-local-variables                          8   0%
                + font-lock-mode                                    2   0%
               + run-hooks                                        331   9%
              + file-truename                                      12   0%
              + set-buffer-multibyte                                6   0%
              + insert-file-contents                                3   0%
                abbreviate-file-name                                1   0%
             + file-truename                                       20   0%
             + find-buffer-visiting                                18   0%
             + create-file-buffer                                  14   0%
               abbreviate-file-name                                 1   0%
            + org-find-base-buffer-visiting                       108   2%
             org-refresh-category-properties                       21   0%
             org-refresh-properties                                13   0%
           + org-set-regexps-and-options                            9   0%
           + org-refresh-effort-properties                          8   0%
             org-refresh-stats-properties                           7   0%
             org-check-agenda-file                                  1   0%
           + org-in-commented-heading-p                             1   0%
          + org-agenda-mode                                         4   0%
          + org-agenda-files                                        4   0%
         + apply                                                   59   1%
         + org-agenda-finalize                                     20   0%
         + org-agenda-finalize-entries                             12   0%
         + org-agenda-files                                         4   0%
           org-days-to-iso-week                                     1   0%
           org-check-agenda-file                                    1   0%
           jit-lock-after-change                                    1   0%
           put-text-property                                        1   0%
         + add-text-properties                                      1   0%
   + helm-M-x                                                     178   4%
+ ...                                                             922  25%
+ redisplay_internal (C function)                                   4   0%
+ timer-event-handler                                               1   0%

Unscientific Stop-Watching

Some unscientific stop-watching averaged out over three attempts gave the following results:

Doom first launch: ~ 12.5 s.
Doom subsequent launches: ~ 1.5 s.
Vanilla first launch: ~ 11 s.
Vanilla subsequent launches: ~ 1 s.

With ratios 12.5 / 11 ~ 13.6 % respective 1.5 / 1 ~ 50 % (not very interesting, could be very wrong). Which is pretty good definitely usable now, thanks again!

As of e86ecf6 and 4209454 that optimization (and two more) are now in our lang/org module. The two extra optimizations should reduce how much time org-agenda spends in doom--optimize-for-large-files-a. More testing needs to be done to ensure no side-effects arise from these fixes, but for now I'll consider this resolved. Let me know if performances issues arise again and I'll reopen this.

Thanks for bringing it to my attention!

Unfortunately, the reported data above is not accurate.

It was run with the default init.el. When commenting out desired modules in init.el the agenda load time is close to 40 s. I haven't found out which modules that cause this. This is with default packages.el and config.el, except for adding the agenda files, i.e., (add-to-list 'org-agenda-files dir).

However, there also seems to be a regression with the default config (init.el): now the subsequent agenda load times are over 5 s.

The size of my agenda files have not grown by any significant amount since previous reports.

Was this page helpful?
0 / 5 - 0 ratings