blob: 234ab9db09cb19371478835c131eaaa2ad2cc318 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#+TITLE: Cache
#+DATE: [2020-07-29 Wed 11:58]
#+KEYWORDS: fc
* Motivation
Even with the AWK based indexer, indexing cards before each review
gets slow if there are a lot of files / cards.
To work around this, the indexer can be run only one time,
caching the results in a hash table.
Advises are added to `delete-file' and `rename-file'
remove / update keys from the hash table.
Changes to existing files & new files are detected with a
~before-save-hook~ on org-mode files.
During a review many files are changed and saved. To keep this as
fast as possible, instead of re-processing files after each save,
changed files are collected in `org-fc-cache-queue' and reprocessed in
bulk the next time the cache is accessed.
Assuming only a small subset of the flashcard files is changed between
reviews, this is much faster than building the full index ch time.
* Activation
Caching can be activated/deactivated with ~M-x org-fc-cache-mode~.
To activate this mode when Emacs starts,
activate it in your configuration:
#+begin_src emacs-lisp
(org-fc-cache-mode)
#+end_src
* Performance
** Setup
#+begin_src fish :exports results
echo (org-files | xargs grep ":fc:" | wc -l) " cards"
echo (org-files | wc -l) " files"
org-files | xargs wc -l | tail -n 1 | sed "s/total/lines/g"
#+end_src
#+RESULTS:
| 18348 | cards |
| 2478 | files |
| 475860 | lines |
** Benchmarks :noexport:
#+begin_src emacs-lisp
(defun my-org-fc-cache-benchmarks ()
(list
(list "Dashboard" (benchmark 1 '(org-fc-dashboard 'all)))
(list "Index Cards in Subdirectory" (benchmark 1 '(length (org-fc-index '(:paths "~/org/deft/")))))
(list "Index Cards with Tag" (benchmark 1 '(length (org-fc-index '(:filter (tag "spanish"))))))))
#+end_src
#+RESULTS:
: my-org-fc-cache-benchmarks
** AWK
#+begin_src emacs-lisp :exports results
(let ((org-fc-index-function #'org-fc-awk-filter-index))
(my-org-fc-cache-benchmarks))
#+end_src
#+RESULTS:
| Dashboard | Elapsed time: 3.642393s |
| Index Cards in Subdirectory | Elapsed time: 0.502262s |
| Index Cards with Tag | Elapsed time: 3.266725s (0.244461s in 1 GCs) |
** Cache
#+begin_src emacs-lisp :exports results
(let ((org-fc-index-function #'org-fc-cache-filter-index))
(cons
(list "Initial Cache Build" (benchmark 1 '(org-fc-cache-build)))
(my-org-fc-cache-benchmarks)))
#+end_src
#+RESULTS:
| Initial Cache Build | Elapsed time: 2.982310s |
| Dashboard | Elapsed time: 0.673869s |
| Index Cards in Subdirectory | Elapsed time: 0.026792s |
| Index Cards with Tag | Elapsed time: 0.040647s |
Dashboard performance will be improved once a card's review history is
cached, too.
|