From 67617254bc4bc63e2f53f6e9faeaa8fd3dc4ae03 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 28 Sep 2019 12:23:31 -0400 Subject: [PATCH] Optimize save-place caching By reducing its limit from 200 to 100 (its default is 400) and by *not* prettifying its cache file (pp is much more expensive than prin1). --- core/core-editor.el | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/core-editor.el b/core/core-editor.el index 8a3798a76..f65b4b14c 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -198,12 +198,22 @@ successfully sets indent_style/indent_size.") :after-call after-find-file dired-initial-position-hook :config (setq save-place-file (concat doom-cache-dir "saveplace") - save-place-forget-unreadable-files t - save-place-limit 200) + save-place-limit 100) + (defadvice! doom--recenter-on-load-saveplace-a (&rest _) "Recenter on cursor when loading a saved place." :after-while #'save-place-find-file-hook (if buffer-file-name (ignore-errors (recenter)))) + + (defadvice! doom--dont-prettify-saveplace-cache-a (orig-fn) + "`save-place-alist-to-file' uses `pp' to prettify the contents of its cache. +`pp' can be expensive for longer lists, and there's no reason to prettify cache +files, so we replace calls to `pp' with the much faster `prin1'." + :around #'save-place-alist-to-file + (cl-letf (((symbol-function #'pp) + (symbol-function #'prin1))) + (funcall orig-fn))) + (save-place-mode +1))