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

org-element-parse-buffer 4.5x slower in Doom vs emacs -q #7835

Open
4 tasks done
cashpw opened this issue Apr 18, 2024 · 11 comments
Open
4 tasks done

org-element-parse-buffer 4.5x slower in Doom vs emacs -q #7835

cashpw opened this issue Apr 18, 2024 · 11 comments
Assignees
Labels
is:upstream Originates from outside the project and cannot be fully addressed here module:lang/org Pertains to Doom's :lang org module re:perf Pertains to startup speed and general snappiness

Comments

@cashpw
Copy link

cashpw commented Apr 18, 2024

I confirm that...

  • I have searched the issue tracker, documentation, FAQ, Discourse, and Google, in case this issue has already been reported/resolved.
  • I have read "How to Debug Issues", and will use it to provide as much information about this issue as possible.
  • The issue can be reproduced on the latest available commit of Doom.
  • The issue can be reproduced on a stable release of Emacs, such as 27, 28, or 29. (Unstable versions end in .50, .60, or .9x)

Expected behavior

With emacs -q on a 15k line org-roam node (note this is an older version of the file):

#+begin_src emacs-lisp
(defmacro measure-time (&rest body)
  "Measure the time it takes to evaluate BODY.

Reference:https://stackoverflow.com/q/23622296"
  `(let ((start-time (current-time)))
     ,@body
     (message "%.06f"
              (float-time (time-since start-time)))))

(measure-time
 (org-element-parse-buffer))
#+end_src

#+RESULTS:
: 0.4...

Current behavior

With Doom Emacs configured with example templates on a 15k line org-roam node (note this is an older version of the file):

#+begin_src emacs-lisp
(defmacro measure-time (&rest body)
  "Measure the time it takes to evaluate BODY.

Reference:https://stackoverflow.com/q/23622296"
  `(let ((start-time (current-time)))
     ,@body
     (message "%.06f"
              (float-time (time-since start-time)))))

(measure-time
 (org-element-parse-buffer))
#+end_src

#+RESULTS:
: 1.830191

Steps to reproduce

Run babel blocks above.

System Information

https://pastebin.com/Q0tU1vqA

@cashpw cashpw added is:bug Something isn't working as intended needs-triage Issue hasn't been assessed yet labels Apr 18, 2024
@cashpw
Copy link
Author

cashpw commented Apr 18, 2024

Memory profile in doomemacs
                                                                264,658,893  99% - command-execute
                                                                264,658,893  99%  - funcall-interactively
                                                                264,658,893  99%   - +org/dwim-at-point
                                                                264,658,893  99%    - if
                                                                264,658,893  99%     - let*
                                                                264,658,893  99%      - cond
                                                                264,658,893  99%       - let
                                                                264,658,893  99%        - org-babel-execute-src-block
                                                                264,658,893  99%         - org-babel-execute:emacs-lisp
                                                                264,658,893  99%          - progn
                                                                264,658,893  99%           - let
                                                                263,818,534  99%            - setq
                                                                263,818,534  99%             - measure-time
                                                                263,818,534  99%              - let
                                                                263,817,737  99%               - org-element-parse-buffer
                                                                263,817,737  99%                - save-excursion
                                                                263,817,737  99%                 - let
                                                                263,807,449  99%                  - org-element--parse-elements
                                                                263,807,449  99%                   - save-excursion
                                                                263,807,449  99%                    - let
                                                                263,807,449  99%                     - while
                                                                263,807,449  99%                      - if
                                                                263,807,449  99%                       - let*
                                                                263,807,449  99%                        - cond
                                                                263,807,449  99%                         - org-element--parse-elements
                                                                263,807,449  99%                          - save-excursion
                                                                263,807,449  99%                           - let
                                                                263,708,617  99%                            - while
                                                                263,708,617  99%                             - if
                                                                263,529,097  99%                              - let*
                                                                211,672,526  79%                               - org-element-copy
                                                                130,067,904  49%                                - if
                                                                130,067,904  49%                                 - progn
                                                                129,835,584  49%                                  - let
                                                                129,582,144  48%                                   - cond
                                                                129,582,144  48%                                    - let
                                                                129,335,040  48%                                     - let
                                                                124,238,784  46%                                      - org-element-map
                                                                109,725,328  41%                                       - let*
                                                                108,404,272  40%                                        - let
                                                                105,553,072  39%                                         - setq
                                                                105,430,576  39%                                          - function
                                                                 99,054,624  37%                                           - cconv-make-interpreted-closure
                                                                 54,627,936  20%                                            - macroexpand-all
                                                                 54,391,392  20%                                             - macroexp--expand-all
                                                                 53,785,248  20%                                              - macroexp--all-forms
                                                                 53,551,872  20%                                               - macroexp--expand-all
                                                                 52,675,392  19%                                                - macroexp--all-forms
                                                                 52,445,184  19%                                                 - macroexp--expand-all
                                                                 51,732,384  19%                                                  - macroexp--all-clauses
                                                                 51,266,688  19%                                                   - macroexp--all-forms
                                                                 48,566,496  18%                                                    - macroexp--expand-all
                                                                 40,916,832  15%                                                     - macroexp--all-forms
                                                                 37,053,984  13%                                                      - macroexp--expand-all
                                                                 36,316,896  13%                                                       - macroexp--all-forms
                                                                 33,200,640  12%                                                        - macroexp--expand-all
                                                                 29,719,008  11%                                                         - macroexp--all-forms
                                                                 27,277,536  10%                                                          - macroexp--expand-all
                                                                 26,558,400  10%                                                           - macroexp--all-forms
                                                                 25,095,840   9%                                                            - macroexp--expand-all
                                                                 24,849,792   9%                                                             - macroexp--all-forms
                                                                 24,849,792   9%                                                              - macroexp--expand-all
                                                                 24,849,792   9%                                                               - macroexp--all-forms
                                                                 24,849,792   9%                                                                - macroexp--expand-all
                                                                 24,849,792   9%                                                                 - macroexp--all-clauses
                                                                 24,366,144   9%                                                                  - macroexp--all-forms
                                                                 22,406,208   8%                                                                   - macroexp--expand-all
                                                                 21,533,952   8%                                                                    - macroexp--all-forms
                                                                 17,426,112   6%                                                                     - macroexp--expand-all
                                                                 16,094,496   6%                                                                      - macroexp--all-forms
                                                                 14,421,792   5%                                                                       - macroexp--expand-all
                                                                 14,071,200   5%                                                                        - macroexp--all-forms
                                                                 13,103,904   4%                                                                         - macroexp--expand-all
                                                                  9,460,704   3%                                                                          - macroexp--all-forms
                                                                  8,231,520   3%                                                                           - macroexp--expand-all
                                                                  5,819,616   2%                                                                            - macroexp--all-forms
                                                                  4,134,240   1%                                                                             - macroexp--expand-all
                                                                  2,054,976   0%                                                                              - macroexp--all-forms
                                                                  1,077,120   0%                                                                               - macroexp--expand-all
                                                                    496,320   0%                                                                                  macroexp--all-forms
                                                                    493,152   0%                                                                              - macroexp--expand-all
                                                                    493,152   0%                                                                                 macroexp--all-forms
                                                                    491,040   0%                                                                              - macroexp--all-clauses
                                                                    491,040   0%                                                                                 macroexp--all-forms
                                                                    954,624   0%                                                                            - macroexp--all-clauses
                                                                    954,624   0%                                                                             - macroexp--all-forms
                                                                    483,648   0%                                                                              - macroexp--expand-all
                                                                    483,648   0%                                                                                 macroexp--all-forms
                                                                  3,155,328   1%                                                                          - macroexp--all-clauses
                                                                  3,155,328   1%                                                                           - macroexp--all-forms
                                                                  1,691,712   0%                                                                            - macroexp--expand-all
                                                                    960,960   0%                                                                               macroexp--all-forms
                                                                    485,760   0%                                                                             - macroexp--expand-all
                                                                    485,760   0%                                                                                macroexp--all-forms
                                                                    472,032   0%                                                                      - macroexp--all-clauses
                                                                    472,032   0%                                                                       - macroexp--all-forms
                                                                    238,656   0%                                                                        - macroexp--expand-all
                                                                    238,656   0%                                                                           macroexp--all-forms
                                                                    246,048   0%                                                             - macroexp--expand-all
                                                                    246,048   0%                                                                macroexp--all-forms
                                                                  2,408,736   0%                                                         - macroexp--all-clauses
                                                                  2,178,528   0%                                                          - macroexp--all-forms
                                                                  1,213,344   0%                                                           - macroexp--expand-all
                                                                    979,968   0%                                                            - macroexp--all-forms
                                                                    481,536   0%                                                             - macroexp--expand-all
                                                                    481,536   0%                                                                macroexp--all-forms
                                                                  6,550,368   2%                                                     - macroexp--all-clauses
                                                                  6,550,368   2%                                                      - macroexp--all-forms
                                                                  5,116,320   1%                                                       - macroexp--expand-all
                                                                  5,116,320   1%                                                        - macroexp--all-forms
                                                                  2,910,336   1%                                                         - macroexp--expand-all
                                                                  2,910,336   1%                                                          - macroexp--all-forms
                                                                    742,368   0%                                                           - macroexp--expand-all
                                                                    742,368   0%                                                              macroexp--all-forms
                                                                    500,544   0%                                                - macroexp--all-clauses
                                                                    500,544   0%                                                 - macroexp--all-forms
                                                                    251,328   0%                                                  - macroexp--expand-all
                                                                    251,328   0%                                                     macroexp--all-forms
                                                                 40,604,256  15%                                            - cconv-fv
                                                                 32,592,384  12%                                             - cconv-analyze-form
                                                                 29,569,056  11%                                              - cconv--analyze-function
                                                                 21,465,312   8%                                               - cconv-analyze-form
                                                                 21,213,984   8%                                                - cconv-analyze-form
                                                                 19,736,640   7%                                                 - cconv-analyze-form
                                                                 17,111,424   6%                                                  - cconv-analyze-form
                                                                 14,054,304   5%                                                   - cconv-analyze-form
                                                                 11,373,120   4%                                                    - cconv-analyze-form
                                                                  9,171,360   3%                                                     - cconv-analyze-form
                                                                  7,477,536   2%                                                      - cconv-analyze-form
                                                                  6,270,528   2%                                                       - cconv-analyze-form
                                                                  4,575,648   1%                                                        - cconv-analyze-form
                                                                  2,880,768   1%                                                         - cconv-analyze-form
                                                                  2,056,032   0%                                                          - cconv-analyze-form
                                                                  1,335,840   0%                                                           - cconv-analyze-form
                                                                    850,080   0%                                                            - cconv-analyze-form
                                                                    373,824   0%                                                               cconv-analyze-form
...
CPU profile in doomemacs
                                                                       1738  99% - ...
                                                                       1625  92%  - #<lambda 0x137082d47a64517e>
                                                                       1625  92%   - let
                                                                       1625  92%    - cond
                                                                       1625  92%     - mapc
                                                                       1621  92%      - #<lambda 0x137082d47a64517e>
                                                                       1621  92%       - let
                                                                       1617  92%        - org-element-parse-buffer
                                                                       1617  92%         - save-excursion
                                                                       1617  92%          - let
                                                                       1612  92%           - org-element--parse-elements
                                                                       1612  92%            - save-excursion
                                                                       1612  92%             - let
                                                                       1612  92%              - while
                                                                       1612  92%               - if
                                                                       1612  92%                - let*
                                                                       1612  92%                 - cond
                                                                       1612  92%                  - org-element--parse-elements
                                                                       1612  92%                   - save-excursion
                                                                       1612  92%                    - let
                                                                       1612  92%                     - while
                                                                       1612  92%                      - if
                                                                       1612  92%                       - let*
                                                                       1596  91%                        - cond
                                                                       1596  91%                         - org-element--parse-elements
                                                                       1588  90%                          - save-excursion
                                                                       1580  90%                           - let
                                                                       1576  90%                            - while
                                                                       1576  90%                             - if
                                                                       1576  90%                              - let*
                                                                       1556  88%                               - org-element-copy
                                                                        864  49%                                - if
                                                                        864  49%                                 - progn
                                                                        860  49%                                  - let
                                                                        852  48%                                   - cond
                                                                        848  48%                                    - let
                                                                        848  48%                                     - let
                                                                        832  47%                                      - org-element-map
                                                                        660  37%                                       - let*
                                                                        644  36%                                        - let
                                                                        616  35%                                         - setq
                                                                        612  34%                                          - function
                                                                        572  32%                                           - cconv-make-interpreted-closure
                                                                        416  23%                                            - macroexpand-all
                                                                        416  23%                                             - macroexp--expand-all
                                                                        412  23%                                              - macroexp--all-forms
                                                                        412  23%                                               - macroexp--expand-all
                                                                        412  23%                                                - macroexp--all-forms
                                                                        412  23%                                                 - macroexp--expand-all
                                                                        408  23%                                                  - macroexp--all-clauses
                                                                        404  23%                                                   - macroexp--all-forms
                                                                        396  22%                                                    - macroexp--expand-all
                                                                        328  18%                                                     - macroexp--all-forms
                                                                        308  17%                                                      - macroexp--expand-all
                                                                        268  15%                                                       - macroexp--all-forms
                                                                        268  15%                                                        - macroexp--expand-all
                                                                        196  11%                                                         - macroexp--all-forms
                                                                        188  10%                                                          - macroexp--expand-all
                                                                        136   7%                                                           - macroexp--all-forms
                                                                        136   7%                                                            - macroexp--expand-all
                                                                        116   6%                                                             - macroexp--all-forms
                                                                        116   6%                                                              - macroexp--expand-all
                                                                        104   5%                                                               - macroexp--all-forms
                                                                        100   5%                                                                - macroexp--expand-all
                                                                         88   5%                                                                 - macroexp--all-clauses
                                                                         88   5%                                                                  - macroexp--all-forms
                                                                         84   4%                                                                   - macroexp--expand-all
                                                                         56   3%                                                                    - macroexp--all-forms
                                                                         52   2%                                                                     - macroexp--expand-all
                                                                         24   1%                                                                      - macroexp--all-forms
                                                                         16   0%                                                                       - macroexp--expand-all
                                                                          4   0%                                                                          macroexp-macroexpand
                                                                          4   0%                                                                          macroexp--all-forms
                                                                          8   0%                                                                      - macroexp--all-clauses
                                                                          8   0%                                                                       - macroexp--all-forms
                                                                          8   0%                                                                        - macroexp--expand-all
                                                                          4   0%                                                                           macroexp--all-forms
                                                                          4   0%                                                                      macroexp--expand-all
                                                                          4   0%                                                               - macroexp--all-clauses
                                                                          4   0%                                                                  macroexp--all-forms
                                                                          4   0%                                                               macroexp--expand-all
                                                                          4   0%                                                               macroexp--all-clauses
                                                                          4   0%                                                               macroexp-macroexpand
                                                                         36   2%                                                           - macroexp--all-clauses
                                                                         32   1%                                                            - macroexp--all-forms
                                                                         28   1%                                                             - macroexp--expand-all
                                                                          4   0%                                                                macroexp-macroexpand
                                                                          4   0%                                                              - macroexp--expand-all
                                                                          4   0%                                                                 macroexp--all-forms
                                                                          4   0%                                                                macroexp--all-forms
                                                                         24   1%                                                         - macroexp--all-clauses
                                                                         24   1%                                                          - macroexp--all-forms
                                                                         16   0%                                                           - macroexp--expand-all
                                                                          4   0%                                                              macroexp--all-forms
                                                                          4   0%                                                           macroexp-macroexpand
                                                                          4   0%                                                         macroexp-macroexpand
                                                                         44   2%                                                     - macroexp--all-clauses
                                                                         44   2%                                                      - macroexp--all-forms
                                                                         40   2%                                                       - macroexp--expand-all
                                                                         40   2%                                                        - macroexp--all-forms

...

@cashpw
Copy link
Author

cashpw commented Apr 18, 2024

Memory profile in `emacs -q`
    135,193,280 100% - command-execute
    135,193,280 100%  - funcall-interactively
    135,193,280 100%   - org-ctrl-c-ctrl-c
    135,193,280 100%    - org-babel-execute-src-block
    135,193,280 100%     - org-babel-execute:emacs-lisp
    135,193,280 100%      - progn
    135,193,280 100%       - let
    131,508,297  97%        - setq
    131,508,297  97%         - measure-time
    131,508,297  97%          - let
    131,508,196  97%           - org-element-parse-buffer
    131,495,340  97%            - org-element--parse-elements
    131,369,556  97%             - org-element--parse-elements
     92,512,213  68%              - org-element--current-element
     88,279,246  65%               - org-element-headline-parser
     41,379,638  30%                - org-element--parse-objects
     38,172,702  28%                 - org-element--object-lex
     35,443,872  26%                  - org-element-link-parser
      6,655,448   4%                   - org-link-unescape
        386,704   0%                      replace-regexp-in-string
        556,120   0%                     org-link-expand-abbrev
        432,864   0%                     replace-regexp-in-string
          3,262   0%                  + org-element-italic-parser
          3,104   0%                    org-element-citation-parser
      1,674,704   1%                 + org-element--parse-objects
      2,950,288   2%                + rx-to-string
      1,573,832   1%                  org-element--get-node-properties
      1,380,416   1%                  replace-regexp-in-string
        133,056   0%               + org-get-limited-outline-regexp
         12,568   0%               + org-element-src-block-parser
          7,200   0%                 org-element--collect-affiliated-keywords
          5,124   0%                 org-element-paragraph-parser
          4,096   0%                 org-element-section-parser
          3,072   0%                 org-element-keyword-parser
          2,469   0%                 org-element-table-parser
          1,024   0%                 org-element-property-drawer-parser
          1,024   0%                 org-element-fixed-width-parser
     33,014,415  24%              + org-element--parse-elements
      4,989,200   3%              + org-element-copy
         66,528   0%                apply
          5,416   0%              + org-element--parse-objects
         66,648   0%             + org-element--current-element
          1,056   0%               org-element-copy
         12,856   0%            + org-element-org-data-parser
             16   0%           + message
      3,684,352   2%          profiler-report
            631   0%          profiler-start
              0   0%   ...
CPU profile in `emacs -q`
         436  96% - command-execute
         436  96%  - funcall-interactively
         436  96%   - org-ctrl-c-ctrl-c
         436  96%    - org-babel-execute-src-block
         436  96%     - org-babel-execute:emacs-lisp
         436  96%      - progn
         436  96%       - let
         428  94%        - setq
         428  94%         - measure-time
         428  94%          - let
         428  94%           - org-element-parse-buffer
         428  94%            - org-element--parse-elements
         416  91%             - org-element--parse-elements
         236  51%              - org-element--current-element
         216  47%               - org-element-headline-parser
         112  24%                - org-element--parse-objects
          80  17%                 - org-element--object-lex
          60  13%                  - org-element-link-parser
          16   3%                     org-link-unescape
           4   0%                     org-link-expand-abbrev
          28   6%                 - org-element--parse-objects
          20   4%                    org-element--object-lex
          12   2%                  org-element--get-node-properties
           4   0%                  org-element--get-time-properties
         156  34%              - org-element--parse-elements
          80  17%               - org-element--parse-elements
          32   7%                - org-element--parse-elements
          16   3%                 - org-element--current-element
           4   0%                    org-element-node-property-parser
          12   2%                   org-element-copy
           4   0%                 - org-element--parse-elements
           4   0%                    org-element--current-element
          24   5%                - org-element--current-element
           4   0%                   org-element--cache-find
          12   2%                  org-element-copy
          56  12%               - org-element--current-element
          28   6%                  org-element-section-parser
           4   0%                  org-element--cache-find
          12   2%               - org-element-copy
           4   0%                  org-element-map
          12   2%                org-element-copy
           4   0%             - org-element--current-element
           4   0%                org-element-headline-parser
           4   0%          profiler-start
           4   0%          profiler-report
          18   3% - ...
          18   3%    Automatic GC

@cashpw
Copy link
Author

cashpw commented Apr 18, 2024

  • I'm not sure why the profiler is more detailed (i.e. mentions the let* and while, etc)
  • The big difference, as far as I can see, is org-element-copy being 79% in doomemacs versus 3% in emacs -q

@hlissner
Copy link
Member

I haven't had time to properly bisect org, but it seems that these performance issues were introduced during recent bumps. A brief history:

That's markedly improved the worst cases, but if this issue is any indications, I'm guessing we're not totally out of the woods.

There is a lot of work between emacs-straight/org-mode@7a6bb09 and their HEAD (emacs-straight/org-mode@1ae978f) so it's difficult to pin-point the cause, but here are some things for you to try:

@hlissner hlissner added re:perf Pertains to startup speed and general snappiness module:lang/org Pertains to Doom's :lang org module is:upstream Originates from outside the project and cannot be fully addressed here and removed is:bug Something isn't working as intended needs-triage Issue hasn't been assessed yet labels Apr 18, 2024
@cashpw
Copy link
Author

cashpw commented Apr 18, 2024

Unpin org. Maybe this has been addressed upstream recently.

#7835 (comment)

I added the following to packages.el

(unpin! org org-contrib)

and re-ran the benchmark:

#+begin_src emacs-lisp
(benchmark 1 '(org-element-parse-buffer))
#+end_src

#+RESULTS:
: Elapsed time: 1.010177s (0.205194s in 1 GCs)

Improved, but still ~2.25x. I'll dig in later tonight.

@hlissner
Copy link
Member

hlissner commented Apr 18, 2024

I mean some slow down is unavoidable. Vanilla Doom enables a few expensive features that are disabled in vanilla Org/Emacs, like org-startup-indented (i.e. org-indent-mode), org-fontify-quote-and-verse-blocks, org-startup-folded != showeverything, etc, so without establishing some parity between the two test cases, it's hard to tell where the "too slow" cut-off point is.

@cashpw
Copy link
Author

cashpw commented Apr 18, 2024

That's a good point, and maybe I'm going about this the wrong way. This issue is an XY problem. The original problem is that this file takes a long time to save. I had identified org-element-parse-buffer as a primary contributor.

#+begin_src emacs-lisp
(defmacro measure-time (&rest body)
  "Measure the time it takes to evaluate BODY.

Reference:https://stackoverflow.com/q/23622296"
  `(let ((start-time (current-time)))
     ,@body
     (message "%.06f"
              (float-time (time-since start-time)))))
(measure-time
 (save-buffer))
#+end_src

#+RESULTS:
: 13.644738

This is my largest file by far, so it's an outlier. Maybe a better course would be to disable expensive functionality in this buffer in particular.


#+begin_src emacs-lisp
`(,(length (org-map-entries t "LEVEL=1"))
,(length (org-map-entries t "LEVEL=2"))
,(length (org-map-entries t "LEVEL=3"))
,(length (org-map-entries t "LEVEL=4"))
)
#+end_src

#+RESULTS:
| 9 | 3910 | 29 | 0 |
#+begin_src emacs-lisp :tangle config-personal.el :results none
(set-eglot-client!
 'org-mode
 '("vale-ls"))

(add-hook! 'org-mode-hook
           #'eglot-ensure)
#+end_src

Looks like org-roam is the primary contributor. I copied the file into a non-org-roam directory, /tmp, and (save-buffer) runs in ~1 second.

@cashpw
Copy link
Author

cashpw commented Apr 18, 2024

I’ve improved performance dramatically (down to <1s from ~14s) by:

  1. Disabling org-encrypt-entries, which called out to org-element-cache-map which accounted for ~94% of the memory (per the profiler):

    (after! org-crypt
      (advice-add
       'org-encrypt-entries
       :override #'ignore))
  2. Limit org-roam-link-replace-at-point (through org-roam-link-replace-all) to roam: links:

    (after! org-roam
      ;; Override to only replace if it's a roam link.
      (defun org-roam-link-replace-all ()
        "Replace all \"roam:\" links in buffer with \"id:\" links."
        (interactive)
        (org-with-point-at 1
          (while (re-search-forward org-link-bracket-re nil t)
            (when (s-starts-with-p
                   "roam:"
                   (match-string 1))
              (org-roam-link-replace-at-point))))))
  3. Disable org-roam auto-sync and instead sync when afk:

    (after! org-roam
      ;; Don't auto-sync
      (org-roam-db-autosync-disable)
      ;; Sync when I'm away from keyoard.
      (setq
       cashpw/org-roam-sync-timer (run-with-idle-timer
                                   60
                                   t
                                   (lambda ()
                                     (let* ((org-roam-directory
                                             cashpw/path--notes-dir)
                                            (org-roam-db-location
                                             (expand-file-name
                                              "org-roam.db"
                                              org-roam-directory)))
                                       (message "Syncing roam database ")
                                       (org-roam-db-sync))))))

@cashpw cashpw closed this as completed Apr 18, 2024
@hlissner
Copy link
Member

hlissner commented Apr 18, 2024

Good finds. I'll look into adapting them to the Org module. I'll keep this open until I do.

@hlissner hlissner reopened this Apr 18, 2024
@hlissner hlissner added this to the modules v24.05 milestone Apr 18, 2024
@hlissner hlissner self-assigned this Apr 18, 2024
@yantar92
Copy link

FYI, the CPU profile indicates that Org mode is not even byte-compiled.

@meedstrom
Copy link

meedstrom commented Apr 24, 2024

And FYI, org-roam-db-autosync-mode is inexactly named; it does more than just resync the file on save. So you might want to think about that.

Here's what it does when enabled -- all pretty straightforward except the find-file hook:

      (add-hook 'find-file-hook  #'org-roam-db-autosync--setup-file-h)
      (add-hook 'kill-emacs-hook #'org-roam-db--close-all)
      (advice-add #'rename-file :after  #'org-roam-db-autosync--rename-file-a)
      (advice-add #'delete-file :before #'org-roam-db-autosync--delete-file-a)

The find-file-hook, in turn, runs org-roam-find-file-hook if it's an org-roam file, and that hook contains these functions:

(org-roam-buffer--setup-redisplay-h 
 org-roam--register-completion-functions-h
 org-roam--replace-roam-links-on-save-h
 org-roam-db-autosync--setup-update-on-save-h)

So among other things, you are entirely disabling the replace-roam-links functionality, so the limitation you did above is moot ;-)

I have some experience fiddling with this thing, so what I would actually suggest is to keep autosync-mode on, don't reinvent the wheel, and then just set the option org-roam-db-update-on-save to nil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:upstream Originates from outside the project and cannot be fully addressed here module:lang/org Pertains to Doom's :lang org module re:perf Pertains to startup speed and general snappiness
Projects
Status: In progress
Status: Blocked
Development

No branches or pull requests

4 participants