From b4248b422666f0ec93dbee0796c9e5ec7fcda3a9 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Fri, 18 Dec 2020 18:55:20 +0100 Subject: [PATCH] SLY: Preload all Nyxt dependencies for fastest startup. --- .emacs.d/lisp/init-sly.el | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/.emacs.d/lisp/init-sly.el b/.emacs.d/lisp/init-sly.el index 3bde85e2..4a2bc171 100644 --- a/.emacs.d/lisp/init-sly.el +++ b/.emacs.d/lisp/init-sly.el @@ -1,5 +1,18 @@ (require 'patch-sly) +(defun ambrevar/prepare-sbcl-for-nyxt () ; TODO: Move this to a cl-flet. + (let ((file (make-temp-file "sbcl"))) + (with-temp-file file + (insert + (format "%S" + '(mapc #'asdf:load-system + (delete-if (lambda (s) + (string= "nyxt" (subseq s 0 (min (length s) 4)))) + (append + (asdf:system-depends-on (asdf:find-system :nyxt)) + (asdf:system-depends-on (asdf:find-system :nyxt/gtk)))))))) + file)) + (when (executable-find "lisp-repl-core-dumper") ;; Warning: ,restart-lisp does not take changes into account, the buffer must be re-created. (setq sly-lisp-implementations @@ -12,12 +25,14 @@ ;; glib is needed to export GIO_EXTRA_MODULES. "--ad-hoc" "glib" "glib-networking" "gsettings-desktop-schemas" "gnupg" "--" "sbcl")) - ;; Faster, but not pure. TODO: Can we purify it? Run it in a container? - (sbcl-nyxt-fast + (sbcl-nyxt-fast ;; Faster, but not pure. TODO: Can we purify it? Run it in a container? Try `env -i bash --noprofile --norc...`. + ;; TODO: Add easy way to reload: must delete profile. No need to delete dump if we use -f. + ;; TODO: Extract to a separate function. (lambda () - ;; TODO: Replace root when source has changed? + ;; TODO: Replace root when guix.scm is newer. (let ((root (expand-file-name "~/.guix-temp-profiles/nyxt")) - (cache (expand-file-name "~/.cache/lisp-repl-core-nyxt"))) + (cache (expand-file-name "~/.cache/lisp-repl-core-nyxt")) + (setup-file (ambrevar/prepare-sbcl-for-nyxt))) (unless (file-exists-p root) (make-directory (file-name-directory root) :parents) (call-process "guix" nil nil nil @@ -32,8 +47,9 @@ "coreutils" "lisp-repl-core-dumper" "--" "env" (concat "LISP_REPL_CORE_PATH=" cache) - "lisp-repl-core-dumper" "sbcl")) - ;; TODO: Include Nyxt Lisp deps in core dump? + "lisp-repl-core-dumper" "-f" "-g" (format "--load %s" setup-file) "sbcl") + (let ((delete-by-moving-to-trash nil)) + (delete-file setup-file))) `(("bash" "-c" ,(concat (format "source '%s/etc/profile'" root) " && LISP_REPL_CORE_PATH=" cache