From d8979bb87a0d3c8839481fa11bf53edab834d940 Mon Sep 17 00:00:00 2001 From: Richard Boyechko Date: Sun, 25 Jun 2023 19:34:14 -0700 Subject: [PATCH 1/3] Restructure zk--id-list to take fuller advantage of passed zk-alist This is just a slight change in the logic, so nothing has changed aside from big performance improvement when ZK-ALIST is passed but STR is not. --- zk.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk.el b/zk.el index de26758..83f217b 100644 --- a/zk.el +++ b/zk.el @@ -347,7 +347,7 @@ The ID is created using `zk-id-time-string-format'." Optional search for STR in note title, case-insenstive. Takes an optional ZK-ALIST, for efficiency if `zk--id-list' is called in an internal loop." - (if str + (if (or str zk-alist) (let ((zk-alist (or zk-alist (zk--alist))) (case-fold-search t) (ids)) From 46efaafac7eea0a70a091367f099bce0ecefe4c3 Mon Sep 17 00:00:00 2001 From: Richard Boyechko Date: Wed, 28 Jun 2023 14:27:01 -0700 Subject: [PATCH 2/3] Fix zk-desktop-make-buttons to pass on zk-alist to zk--id-list --- zk-desktop.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk-desktop.el b/zk-desktop.el index 25cead7..70539a8 100644 --- a/zk-desktop.el +++ b/zk-desktop.el @@ -234,7 +234,7 @@ To quickly change this setting, call `zk-desktop-add-toggle'." ;; replace titles (goto-char (point-min)) (let* ((zk-alist (zk--alist)) - (ids (zk--id-list))) + (ids (zk--id-list nil zk-alist))) (while (re-search-forward zk-id-regexp nil t) (let* ((beg (line-beginning-position)) (end (line-end-position)) From 00111c46623f66861c3e2cb730e3ae7d30519889 Mon Sep 17 00:00:00 2001 From: Richard Boyechko Date: Sun, 16 Jul 2023 15:46:09 -0700 Subject: [PATCH 3/3] Fix several other places where zk-alist is not passed to zk--id-list A lot of these are very difficult to benchmark, but considering the following benchmarks, there is potential to considerably speed up various zk-desktop and zk-index commands. The change to `zk-index-query-files` will likely result in greatest benefit, since we go from running `zk--alist` three times to running it once. `zk--parse-id` did not pass on its zk-alist to `zk--id-list` either. ``` === bm/zk--id-list+use-zk-alist (10 reps) at 2023-07-16 15:26 === ((zk--id-list/orig)) => 3049 results in 0.97 sec (inc. 0.56 sec for 0 GCs) ((zk--id-list)) => 3049 results in 0.95 sec (inc. 0.56 sec for 0 GCs) ((zk--id-list/orig nil zk-alist)) => 3049 results in 0.98 sec (inc. 0.58 sec for 0 GCs) ((zk--id-list nil zk-alist)) => 3049 results in 0.03 sec (inc. 0.02 sec for 0 GCs) ``` --- zk-index.el | 9 +++++---- zk.el | 14 +++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/zk-index.el b/zk-index.el index fa324da..bd4096d 100644 --- a/zk-index.el +++ b/zk-index.el @@ -376,10 +376,11 @@ items listed first.") (defun zk-index-query-files () "Return narrowed list of notes, based on focus or search query." (let* ((command this-command) + (zk-alist (zk--alist)) (scope (if (zk-index-narrowed-p (buffer-name)) (zk-index--current-id-list (buffer-name)) (setq zk-index-query-terms nil) - (zk--id-list))) + (zk--id-list nil zk-alist))) (string (read-string (cond ((eq command 'zk-index-focus) "Focus: ") ((eq command 'zk-index-search) @@ -387,12 +388,12 @@ items listed first.") nil 'zk-search-history)) (query (cond ((eq command 'zk-index-focus) - (zk--id-list string)) + (zk--id-list string zk-alist)) ((eq command 'zk-index-search) - (zk--grep-id-list string)))) + (zk--grep-id-list string zk-alist)))) (ids (mapcar (lambda (x) (when (member x scope) x)) query)) - (files (zk--parse-id 'file-path (remq nil ids)))) + (files (zk--parse-id 'file-path (remq nil ids) zk-alist))) (add-to-history 'zk-search-history string) (when files (let ((mode-line (zk-index-query-mode-line command string))) diff --git a/zk.el b/zk.el index 83f217b..3ba0349 100644 --- a/zk.el +++ b/zk.el @@ -361,9 +361,10 @@ an internal loop." (defun zk-id-p (id) "Return t if ID is already in use as a zk-id." - (when (and (listp (zk--id-list)) - (member id (zk--id-list))) - t)) + (let ((zk-alist (zk--alist))) + (when (and (listp (zk--id-list nil zk-alist)) + (member id (zk--id-list nil zk-alist))) + t))) (defun zk--current-id () "Return the ID of zk note in current buffer." @@ -508,9 +509,8 @@ in an internal loop." (zk--singleton-p ids)) (car (zk--directory-files t (car ids)))) (t - (let* ((zk-alist (or zk-alist - (zk--alist))) - (zk-id-list (zk--id-list)) + (let* ((zk-alist (or zk-alist (zk--alist))) + (zk-id-list (zk--id-list nil zk-alist)) (return (cond ((eq target 'file-path) (cond ((stringp ids) @@ -828,7 +828,7 @@ Optionally call a custom function by setting the variable (defun zk--links-in-note-list () "Return list of zk files that are linked from the current buffer." (let* ((zk-alist (zk--alist)) - (zk-ids (zk--id-list)) + (zk-ids (zk--id-list nil zk-alist)) id-list) (save-buffer) (save-excursion