If I'm using use-package
in a file that I plan to byte-compile, can I still leverage Emacs' byte-compile-dynamic
setting to lazy-load compiled function definitions? From the Elisp manual:
With dynamic function loading, loading the file doesn’t fully read the function definitions in the file. Instead, each function definition contains a place-holder which refers to the file. The first time each function is called, it reads the full definition from the file, to replace the place-holder.
So, for example, if my init.el loads a file,
(require 'my-persistence (concat user-emacs-directory "my-persistence")
in which I've put persistence-related settings,
(use-package savehist
:commands savehist-mode
:config
(setq savehist-autosave-interval 60)
(defun foo () ...)
(defun bar () ...)
(defun baz () ...))
(provide 'my-persistence)
I could add -*-byte-compile-dynamic: t;-*-
to the top of that file, in hopes that lazy-loading the compiled function definitions of foo
, bar
, and baz
reduces the time spent evaluating the :config
section.
I imagine it playing out like:
- my-persistence.elc is loaded
- user calls
savehist-mode
savehist
package is loaded:config
section is evaluatedsavehist-autosave-interval
is set to 60- lazy-loading defers the full definitions of
foo
,bar
, andbaz
- user calls
foo
foo
's full definition is loaded
I tried it out, and :config
still behaves as expected, but I don't know how to check whether foo
, bar
and baz
are in fact being lazy-loaded.