emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PERFORMANCE] Why some org code is so deep invoked?


From: Ihor Radchenko
Subject: Re: [PERFORMANCE] Why some org code is so deep invoked?
Date: Sat, 13 Aug 2022 14:50:30 +0800

"Christopher M. Miles" <numbchild@gmail.com> writes:

>          668  28%                                    - 
> org-agenda-prepare-buffers
> ...
>          523  22%                                              - 
> org--tag-add-to-alist

I have a suspicion where the bottleneck is.
Can you try the attached patch?

>From 1f5cdbd05c7012962ba3f12671805d77f52d836e Mon Sep 17 00:00:00 2001
Message-Id: 
<1f5cdbd05c7012962ba3f12671805d77f52d836e.1660373309.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Sat, 13 Aug 2022 14:45:01 +0800
Subject: [PATCH] org-agenda-prepare-buffers: Avoid quadratic behavior when
 merging tags

* lisp/org.el (org-agenda-prepare-buffers): Use the shortest list as
the first argument in `org--tag-add-to-alist'.

`org--tag-add-to-alist' is looping over the first argument.  When we
use the accumulated tags as the first argument, each buffer tag will
need to be looped over N_buffers/2 times on average, creating
quadratic complexity.  Avoid this.

Reported in 
https://orgmode.org/list/62f66552.050a0220.ed346.ac05SMTPIN_ADDED_BROKEN@mx.google.com
---
 lisp/org.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 4eef56f45..b21bdf291 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15196,8 +15196,8 @@ (defun org-agenda-prepare-buffers (files)
                 (append org-todo-keyword-alist-for-agenda org-todo-key-alist))
           (setq org-tag-alist-for-agenda
                 (org--tag-add-to-alist
-                 org-tag-alist-for-agenda
-                 org-current-tag-alist))
+                 org-current-tag-alist
+                  org-tag-alist-for-agenda))
           ;; Merge current file's tag groups into global
           ;; `org-tag-groups-alist-for-agenda'.
           (when org-group-tags
-- 
2.35.1


-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92

reply via email to

[Prev in Thread] Current Thread [Next in Thread]