diff options
| author | Andrew Guschin <guschin@altlinux.org> | 2024-11-26 20:34:25 +0400 |
|---|---|---|
| committer | Andrew Guschin <guschin@altlinux.org> | 2024-11-26 20:34:25 +0400 |
| commit | 581d99339a522675b7bfc619e84ccf33340535d2 (patch) | |
| tree | 6d8422e2b5299277e7115a4d0af0c40f4bc3057e /init.el | |
| parent | 48abb4c18b78f96d66c39531bfc6c28983797849 (diff) | |
speed up startup by using org tangle only when config.org changed
To determine if config is changed, we can calculate its current md5 and compare it with previous
one. If file with previous checksum doesn't exist, then we should bootstrap config anyway, so
this will invoke tangle. In most cases, Emacs starts with the same config, so this is a nice
optimization.
Diffstat (limited to 'init.el')
| -rw-r--r-- | init.el | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -1 +1,24 @@ -(org-babel-load-file (expand-file-name "config.org" user-emacs-directory)) +;; Set up benchmark-init of initialization early inside init.el to correctly benchmark load time +(when (package-installed-p 'benchmark-init) + (require 'benchmark-init) + (add-hook 'after-init-hook 'benchmark-init/deactivate)) + +(setq checksum-path (expand-file-name ".config-checksum" user-emacs-directory)) +(setq config-path (expand-file-name "config.org" user-emacs-directory)) +(setq config-untangled-path (expand-file-name "config.el" user-emacs-directory)) + +;; Since config is residing inside one file, I can calculate its checksum and tangle config.org only +;; when it was changed. This way loading is significantly faster. +(setq new-checksum (car (split-string (shell-command-to-string (concat "md5sum --zero " config-path))))) +(setq saved-checksum "") +(when (file-exists-p checksum-path) + (setq saved-checksum (with-temp-buffer + (insert-file-contents checksum-path) + (buffer-string)))) +(if (string-equal new-checksum saved-checksum) + (load-file config-untangled-path) + (progn + (write-region new-checksum nil checksum-path) + (setq org-modules '(org-id ol-info org-protocol)) + (org-babel-load-file config-path))) + |