Browse Source

org.el: Avoid excessive memory usage by effort text properties

* lisp/org.el (org-set-effort):
(org-property-next-allowed-value): Do not use text properties cache
for `effort' and `effort-minutes' when org-element-cache is active.
These text properties are superceded by element cache and their only
effect (when cache is active) is extra load on Emacs garbage collector
leading to overall Emacs slowdown.
* lisp/org-clock.el (org-clock-in): Use `org-element-use-cache'
instead of `org-element--cache-active-p' to check if element cache is
active. The latter is too precise and may trigger
`org-refresh-effort-properties' when cache is temporarily disabled by
internal calls.
Ihor Radchenko 3 years ago
parent
commit
0350c7dd71
2 changed files with 12 additions and 9 deletions
  1. 2 1
      lisp/org-clock.el
  2. 10 8
      lisp/org.el

+ 2 - 1
lisp/org-clock.el

@@ -36,6 +36,7 @@
 (declare-function org-element-property "org-element" (property element))
 (declare-function org-element-type "org-element" (element))
 (declare-function org-element--cache-active-p "org-element" ())
+(defvar org-element-use-cache)
 (declare-function org-inlinetask-at-task-p "org-inlinetask" ())
 (declare-function org-inlinetask-goto-beginning "org-inlinetask" ())
 (declare-function org-inlinetask-goto-end "org-inlinetask" ())
@@ -1266,7 +1267,7 @@ time as the start time.  See `org-clock-continuously' to make this
 the default behavior."
   (interactive "P")
   (setq org-clock-notification-was-shown nil)
-  (unless (org-element--cache-active-p)
+  (unless org-element-use-cache
     (org-refresh-effort-properties))
   (catch 'abort
     (let ((interrupting (and (not org-clock-resolving-clocks-due-to-idleness)

+ 10 - 8
lisp/org.el

@@ -12965,9 +12965,10 @@ variables is set."
     ;; Maybe update the effort value:
     (unless (equal current value)
       (org-entry-put nil org-effort-property value))
-    (org-refresh-property '((effort . identity)
-			    (effort-minutes . org-duration-to-minutes))
-			  value)
+    (unless (org-element--cache-active-p)
+      (org-refresh-property '((effort . identity)
+			   (effort-minutes . org-duration-to-minutes))
+		         value))
     (when (equal (org-get-heading t t t t)
 		 (bound-and-true-p org-clock-current-task))
       (setq org-clock-effort value)
@@ -13915,10 +13916,11 @@ completion."
     (beginning-of-line 1)
     (skip-chars-forward " \t")
     (when (equal prop org-effort-property)
-      (org-refresh-property
-       '((effort . identity)
-	 (effort-minutes . org-duration-to-minutes))
-       nval)
+      (unless (org-element--cache-active-p)
+        (org-refresh-property
+         '((effort . identity)
+	   (effort-minutes . org-duration-to-minutes))
+         nval))
       (when (string= org-clock-current-task heading)
 	(setq org-clock-effort nval)
 	(org-clock-update-mode-line)))
@@ -15907,7 +15909,7 @@ When a buffer is unmodified, it is just killed.  When modified, it is saved
 	    (or (memq 'stats org-agenda-ignore-properties)
 		(org-refresh-stats-properties))
 	    (or (memq 'effort org-agenda-ignore-properties)
-                (unless (org-element--cache-active-p)
+                (unless org-element-use-cache
 		  (org-refresh-effort-properties)))
 	    (or (memq 'appt org-agenda-ignore-properties)
 		(org-refresh-properties "APPT_WARNTIME" 'org-appt-warntime))