reddit / emacs
How can I speed up my start up times?
vfclists · 2022-12-13 17:18
I think my start up times are slow because:
1. I have not designed by self-written features to delay loading until they are required because I don't now how
2. because I'm not using `use-package` properly, ie adding the `:bind` etc that delays the loading of packages till their needed.
In case of my own features, ie those I load with `require` how do delay them until they are required?
franburstall · 2022-12-13 18:11
You can use `use-package` on your own features: anything you can `require` is good for `use-package`.
noobCodeKid · 2022-12-13 19:24
Are you using the emacs client?
nv-elisp · 2022-12-13 19:40
Link to the init file. There's no way for anyone to give you any specific advice if you don't provide anything specific to evaluate.
Qudit314159 · 2022-12-13 19:40
Just run Emacs as a daemon and startup times won't matter much.
vfclists · 2022-12-13 20:21
That will be like allowing a peak into my mancave, even worse my bathroom.
Folks are unlikely to survive the trauma.
thetemp_ · 2022-12-13 23:15
Most packages you get from MELPA and whatnot will have already had their autoloads defined on startup. So as long as you don't `require` them, loading will be deferred until you run an autoloaded command. However, with use-package, you will have to use `:defer t` or set `use-package-always-defer` to t in order to prevent use-package from loading those packages immediately when their `use-package` form is reached. (You can omit `:defer t` if you use one of the autoloading keywords.)
For your own features, the simplest method is to set up autoloaded functions, commands, or keymaps using the `autoload` function. Use-package also has a keyword called `:autoload` but it's meant for non-interactive functions. For commands, you're supposed to use the `:commands` keyword.
A couple of other methods you can use to autoload packages are hooks (either `add-hook` or the `:hook` keyword) and setting `auto-mode-alist` (or the `:mode` keyword).
vfclists · 2022-12-13 23:47
> For your own features, the simplest method is to set up autoloaded functions, commands, or keymaps using the autoload function.
Where do I learn these? Are there any howtows outside the official docs?
SlowValue · 2022-12-13 23:49
> In case of my own features, ie those I load with require how do delay them until they are required?
End your elisp files with:
(provide 'MY-FILE1)
Then write a use-package declaration:
(use-package MY-FILE1
:load-path "PATH-TO-MY-FILE1"
;; either delay with commands, file will be required if one of those command is called first time
:commands (MY-FILE1-CMD1 MY-FILE1-CMD-2)
;; or delay with bind, file will be required when you press keybinding, or runn this command first time
:bind ("C-c t" . MY-FILE1-CMD1))
Note: replace UPPERCASE stuff with your own names.
JRollard · 2022-12-13 23:57
If you use [straight](https://github.com/radian-software/straight.el) and override package, you'll get a lot of your desired functionality for free. Straight's docs are excellent. I started banging away on my own setup from scratch, and while not perfect, it does what I want and the total startup time is about 1.5 seconds without doing anything to try to optimize it. If you want to see it, check it out [here](https://github.com/smashedtoatoms/emacs.d). Like I said, there is lots of room for improvement, but it does work for me.
vfclists · 2022-12-14 00:00
not much
noobCodeKid · 2022-12-14 00:04
Thatll fix most of it. Just have the daemon run at startup and only use the client. Thats what I do and I can freely open and close emacs just as quick as a terminal
[deleted] · 2022-12-14 00:04
[deleted]
redguardtoo · 2022-12-14 00:13
As others mentioned, `autoload` is used frequently during startup optmization.
`with-eval-after-load` is also very useful. You can use it to set up the package *after* the package is loaded.
I suggest you read the full documentation of above two APIs.
`run-with-idle-timer` might be useful sometimes.
There are other techniques which you can find in many distributions (doom emacs?),
- place some setup into `early-init.el`
- when a package is required, `load-path` is scanned to locate the package. `load-path` could be reduced to descrease scanning time. Or `require` could be avoided.
- Increase `gc-cons-percentage` and `gc-cons-threshold` temporarily during startup
- minimize/optimize mode line
- other per package optmization techniques.
Ideally the startup time could be 0.5 seconds. But in order to reach this goal, you need a bit knowledge of Emacs Lisp. You also need read the code of other distributions.
Here is my setup, https://github.com/redguardtoo/emacs.d
zoechi · 2022-12-14 00:35
https://www.emacswiki.org/emacs/GccEmacs might help
thetemp_ · 2022-12-14 01:37
Official docs are [best docs](https://www.gnu.org/software/emacs/manual/html_node/elisp/Autoload.html). Maybe you already know, but you can read how any function works by entering "C-h f", then typing the name of the function and Enter. You can also look at its source code if you click on the name of the file that defines it.
The `autoload` function is different from the "autoload cookies" which you might have seen in some source code. (Those are commented lines that begin with ";;;###autoload".) The autoload cookies are scraped by package.el and used to generate an autoload file that gets loaded on startup.
But the `autoload` function has to be called from your init file in order to set up the autoload.
Megasphaera · 2022-12-14 08:05
Have just one single emacs process running on your machine and restart it as little as possible. Use emacsclient as your $EDITOR
_viz_ · 2022-12-14 14:48
Then don't call for cleaning service but look up books on cleaning; from your past posts, looking up info yourself seems like a skill you would benefit from.
tangonov · 2022-12-14 15:29
The best advice anyone can give you is to learn to look within Emacs. Emacs /is/ the official documentation.
`C-h i` gets you started with the help docs. Use `describe-mode` (`M-x describe-mode`/`C-h m`) to learn the keybindings for the help docs.
Look at the "describe functions" to learn how to look up variable and function docs (`M-x describe-function`/`C-h f` or `M-x describe-variable`/`C-h v`).
Check out the apropos feature for finding keywords in symbols throughout Emacs with `M-x apropos`
If all else fails you could always read the source code to learn.