Lazy loading (also known as asynchronous loading) is a technique commonly used in computer programming to defer initialization of an object until the point at which it is needed. It can contribute to efficiency in the program’s operation if properly and appropriately used.
The ‘autoload’ facility lets you register the existence of a function or macro, but put off loading the file that defines it. The first call to the function automatically loads the proper library, in order to install the real definition and other associated code, then runs the real definition as if it had been loaded all along.
This library it’s capable of monitoring arbitrary directories and automatic generate load definitions, also provides interactive functions to trigger the described feature.
This library was designed having vanilla Emacs
in mind, so if
you are missing something, it’ll be necessary to properly
extend it.
Provide an easy (automatic) way to generate autoloads
from
other libraries providing lazy-load
loading across Emacs
.
Lazy-Load | (emacs-init-time) |
No | 4.871672671 seconds |
Yes | 0.489159734 seconds |
I also notice that Emacs
become more stable and fast (guessing),
because exotic
, less used libraries, are loaded only when some
autoload
registered function
is invoked.
- Alpha: 0.0.8
- cl-seq
- autoloads
- filenotify
- dired-aux
Emacs | 27.1 | 28.0 |
FreeBSD | 12.1 | 12.2 |
OpenBSD | 6.8 |
Clone Lazy
repository to an arbitrary location:
$ git clone https://github.com/lambdart/lazy-load ~/.emacs.d/site-elisp/lazy-load
Add Lazy
directory to load-path
in your
Emacs initialization file (init.el
) and load it.
;; add to load-path
(add-to-list 'load-path "/replace/me/to/lazy-load/full/path")
;; load lazy-load feature
(require 'lazy-load nil t)
- Note: For a more dynamic approach:
M-x load-file RET
M-x load-library RET lazy-load RET
- Note: Optional (recommended).
To compile the files to the Elisp
byte-compiled representation:
[at-lazy-load-root-directory]$ make
Set the lazy-load-files-alist
variable, e.g:
(customize-set-variable
'lazy-load-files-alist
(list (cons "site-lisp-loaddefs.el"
(expand-file-name "site-lisp/" user-emacs-directory)))
and invoke: M-x lazy-load-update-autolods RET
Set the variable lazy-load-enable-filenotify-flag
to t
(true), to
generate the load definitions autoloads
automatically when the
monitored directory emits a signal, i.e, when you download (files)
packages to it.
It’s also possible to invoke lazy-load-update-directory-autoloads
interactively:
M-x lazy-load-update-directory-autoloads RET
The procedure will ask for the root directory (where packages
resides) and the referent <file-name-path>
where the
load definitions will be saved.
After the loaddefs
was generated just add it to your init.el
and all the other (require 'packages)
will be unnecessary.
Example:
(require 'site-lisp-loaddefs)
That’s all! :D
- Note: To see all the options from
Emacs
directly, and to customize it, just type:M-x customize-group RET lazy-load RET
.
We have a few available options to customize some aspects of lazy-load
,
even though the behavior will probably stay the same, it’s recommend
to proper set this variables in your initialization file.
lazy-load-files-alist
- Associative list of file-names (loaddefs) destination and respective source path (root) directory, example:
(list (cons "site-lisp-loaddefs.el"
(expand-file-name "site-lisp" user-emacs-directory)))
RESULT: (("site-lisp-loaddefs.el" . "/home/<user>/.emacs.d/site-lisp"))
lazy-load-minor-mode-string
- String to be displayed at mode-line. Default: “lazy-load”
lazy-load-enable-filenotify-flag
- Non-nil means starts to monitor the directories listed at `lazy-load-files-alist’. Default: nil
lazy-load-debug-messages-flag
- Non-nil means show debug messages. Default: nil
lazy-load-timer-interval
- Timer interval in seconds, used to trigger the timer callback function. Default: 8 seconds
lazy-load-idle-seconds
- Idle timer value that will be used by `run-with-idle-timer’. Default: 30 seconds
An object which can be invoked via the ‘command-execute’ primitive, usually due to the user typing in a key sequence “bound” to that command.
A command is usually a function; if the function is written in Lisp, it is made into a command by an ‘interactive’ form in the function definition-prefixes.
- https://www.gnu.org/software/emacs/manual/html_node/elisp/Autoload.html
- https://en.wikipedia.org/wiki/Lazy_loading
MIT
I don't think necessity is the mother of invention. Invention arises directly from idleness, possibly also from laziness. To save oneself trouble.
Agatha Mary Clarissa Miller |