Org-roam gets slow as you accumulate thousands of nodes. The following code fixes it. Requires the packages memoize and vulpea.
Vulpea provides faster versions of org-roam commands, but it depends on its own optimized database. The first time you enable vulpea-db-autosync-mode, you need to eval (org-roam-db-sync 'force) so it can populate that database.
;; Make the commands `org-roam-node-find' & `org-roam-node-insert' faster and
;; often instant.
;; Small drawback: after you just created a node, you can't immediately
;; find it as it won't be in the cache. You must leave Emacs alone for
;; 10 seconds, then it'll enter the cache.
(defun my-vulpea-memo-refresh ()
(memoize-restore #'vulpea-db-query)
(memoize #'vulpea-db-query)
(vulpea-db-query nil))
(defvar my-vulpea-memo-timer (timer-create))
(defun my-vulpea-memo-schedule-refresh (&rest _)
"Schedule a re-caching when the user is idle."
(cancel-timer my-vulpea-memo-timer)
(setq my-vulpea-memo-timer
(run-with-idle-timer 10 nil #'my-vulpea-memo-refresh)))
;; Love this lib. Thank you
(use-package vulpea
:hook ((org-roam-db-autosync-mode . vulpea-db-autosync-enable))
:bind (([remap org-roam-node-find] . vulpea-find)
([remap org-roam-node-insert] . vulpea-insert))
:config
(use-package memoize :demand)
(memoize #'vulpea-db-query)
(advice-add 'org-roam-db-update-file :after 'my-vulpea-memo-schedule-refresh))
Other speed boosts
;; Don't search for "roam:" links (it slows saving on large files)
(setq org-roam-link-auto-replace nil)
;; Speed up `org-roam-db-sync'
;; NOTE: `setopt' breaks it, use `setq'
;; NOTE: Counterproductive on Windows
(setq org-roam-db-gc-threshold most-positive-fixnum)
If you still find it slow to save large files, maybe you have org-crypt configured. It's that package that encrypts/decrypts subtrees.
Doom Emacs' Org module ships it by default, so here's how to disable it in Doom's packages.el:
(package! org-crypt :disable t)