Ver Fonte

Speedup of org-id-update-id-locations

Since this is about performance, a benchmark before this change, on a
set of 519 files with total size of 1500 kb gives the following result:

  519 files scanned, 504 files contains IDs, and 911 IDs found.
  (168.243948 38 2.053949000000003)

After the change the following result:

  519 files scanned, 504 files contains IDs, and 911 IDs found.
  (3.034806 3 0.16445799999999622)

Benchmark done on a a Windows machine with no files previously loaded
into Emacs.

* lisp/org-id.el (org-id-update-id-locations): This function has
gotten a bit of back and forth changes in terms of performance.  One
year ago in 9865e6bd8 and then six months ago in 37a5020bb.
Unfortunately the latest speedup actually was a speed-down.  Speed is
not good again.
Gustav Wikström há 4 anos atrás
pai
commit
19d2f79a0f
1 ficheiros alterados com 25 adições e 22 exclusões
  1. 25 22
      lisp/org-id.el

+ 25 - 22
lisp/org-id.el

@@ -518,28 +518,31 @@ When FILES is given, scan also these files."
          (seen-ids nil)
          (ndup 0)
          (i 0))
-    (dolist (file files)
-      (when (file-exists-p file)
-        (unless silent
-          (cl-incf i)
-          (message "Finding ID locations (%d/%d files): %s" i nfiles file))
-        (with-current-buffer (find-file-noselect file t)
-          (let ((ids nil)
-                (case-fold-search t))
-            (org-with-point-at 1
-              (while (re-search-forward id-regexp nil t)
-                (when (org-at-property-p)
-                  (push (org-entry-get (point) "ID") ids)))
-              (when ids
-                (push (cons (abbreviate-file-name file) ids)
-                      org-id-locations)
-                (dolist (id ids)
-                  (cond
-                   ((not (member id seen-ids)) (push id seen-ids))
-                   (silent nil)
-                   (t
-                    (message "Duplicate ID %S" id)
-                    (cl-incf ndup))))))))))
+    (with-temp-buffer
+      (delay-mode-hooks
+	(org-mode)
+	(dolist (file files)
+	  (when (file-exists-p file)
+            (unless silent
+              (cl-incf i)
+              (message "Finding ID locations (%d/%d files): %s" i nfiles file))
+	    (insert-file-contents file nil nil nil 'replace)
+            (let ((ids nil)
+		  (case-fold-search t))
+              (org-with-point-at 1
+		(while (re-search-forward id-regexp nil t)
+		  (when (org-at-property-p)
+                    (push (org-entry-get (point) "ID") ids)))
+		(when ids
+		  (push (cons (abbreviate-file-name file) ids)
+			org-id-locations)
+		  (dolist (id ids)
+                    (cond
+                     ((not (member id seen-ids)) (push id seen-ids))
+                     (silent nil)
+                     (t
+                      (message "Duplicate ID %S" id)
+                      (cl-incf ndup)))))))))))
     (setq org-id-files (mapcar #'car org-id-locations))
     (org-id-locations-save)
     ;; Now convert to a hash table.