diff options
author | Gustav Wikström <p950gsw@fspa.myntet.se> | 2020-11-04 16:12:44 +0100 |
---|---|---|
committer | Gustav Wikström <p950gsw@fspa.myntet.se> | 2020-11-04 16:41:20 +0100 |
commit | 19d2f79a0f8b511345b07a9f9f4604f24df113e0 (patch) | |
tree | 08cdd6bae10c9c66b79a1352b7831750a4735804 | |
parent | 2d21c0d6860786f5c0063859e46790fbdc5ca178 (diff) | |
download | org-mode-19d2f79a0f8b511345b07a9f9f4604f24df113e0.tar.gz |
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.
-rw-r--r-- | lisp/org-id.el | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/lisp/org-id.el b/lisp/org-id.el index 78ea424..b157461 100644 --- a/lisp/org-id.el +++ b/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. |