Comments (11)
Good finds. I'll look into adapting them to the Org module. I'll keep this open until I do.
from doomemacs.
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.
from doomemacs.
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
...
from doomemacs.
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
from doomemacs.
- I'm not sure why the profiler is more detailed (i.e. mentions the
let*
andwhile
, etc) - The big difference, as far as I can see, is
org-element-copy
being 79% in doomemacs versus 3% inemacs -q
from doomemacs.
I haven't had time to properly bisect org, but it seems that these performance issues were introduced during recent bumps. A brief history:
- emacs-straight/org-mode@7a6bb09 was the last known "fast" commit (what the org module was pinned to until March 29th).
- In 5f5a163, I bumped it to emacs-straight/org-mode@e9c288d, which introduced a lot of performance problems in Org buffers.
- I reverted org to emacs-straight/org-mode@5bdfc02c6fa1 in 5b7d676 to mitigate this.
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:
- Unpin org. Maybe this has been addressed upstream recently.
- Try one of these commits that predate our current pin (emacs-straight/org-mode@e9c288d). It'd help me zero in on where the problem began, and may perhaps inform a bug report upstream:
- emacs-straight/org-mode@bc0e14a (Feb 11)
- emacs-straight/org-mode@fe9bc9e (Feb 28)
- emacs-straight/org-mode@28dc5dd (Mar 8)
- emacs-straight/org-mode@50c51b9 (Mar 22)
- emacs-straight/org-mode@5ff4d54 (Mar 24)
- emacs-straight/org-mode@5bdfc02 (Mar 26) (Where the org module is pinned now)
from doomemacs.
Unpin org. Maybe this has been addressed upstream recently.
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.
from doomemacs.
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.
from doomemacs.
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.
from doomemacs.
I’ve improved performance dramatically (down to <1s from ~14s) by:
-
Disabling
org-encrypt-entries
, which called out toorg-element-cache-map
which accounted for ~94% of the memory (per the profiler):(after! org-crypt (advice-add 'org-encrypt-entries :override #'ignore))
-
Limit
org-roam-link-replace-at-point
(throughorg-roam-link-replace-all
) toroam:
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))))))
-
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))))))
from doomemacs.
FYI, the CPU profile indicates that Org mode is not even byte-compiled.
from doomemacs.
Related Issues (20)
- Yasnippet placeholders not cycling through in the GUI (in C++ and Corfu) HOT 1
- `doom sync -u` deletes `$EMACSDIR/bin` and leaves Doom in broken state HOT 1
- Emacs daemon crash when set-fontset-font is called after a dead X server frame HOT 4
- Error: `which-key-mode’ can’t be used with ‘helm-descbinds-mode’` HOT 1
- `MODE-local-vars-hook` in org mode HOT 1
- Keybinding conflict: org-mode + evil-multiedit
- `doom env` doesn't correctly capture my PATH HOT 3
- Ligature rendering sometimes renders with extra spacing HOT 1
- problem with savehist-mode causing `doom-first-input-hook` to throw an error HOT 2
- doom-module-from-path couldn't handle symbolic links correctly. HOT 3
- setq-default not working for mode-line HOT 4
- anaconda-mode activates despite using (lsp +eglot)
- Void function 'envrc-global-mode-enable-in-buffers' on latest Emacs30
- evil-org-mode-map unbound HOT 5
- Doom CLI breakage HOT 1
- Lsp defition lookup hijacks repl window
- Default keybindings missing/not working HOT 3
- open file using `emacs FILE_NAME` will not trigger `format-onsave` HOT 1
- [bug] switching themes in text "big mode" causes text to get bigger and bigger
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from doomemacs.