Emacs daemon greatly reduces time to load the first frame with emacsclient. However, when visiting a file with emacsclient, subsequent emacsclient frames load much faster than the first.
|Command||Load time (seconds)|
|Emacs daemon||emacs --daemon||30|
|1. emacsclient frame - no file visited||emacsclient -c||<1|
|2. emacsclient frame visiting a file||emacsclient -c "file1.org"||8|
|3. All subsequent emacsclient frames visiting the same file as in (2) with different filename||emacsclient -c "file2.org"||1|
What is slowing down the first emacsclient frame but not subsequent frames? Apparently that first call to emacsclient still loads something that is not being loaded in subsequent calls to emacsclient. Perhaps mode hooks? I can inspect load times for the daemon, which shows load time for individual packages. But I do not know how to inspect load times for each emacsclient frame.
If possible it would be great if the daemon could also take on the loading that seems to be executed during that first call to emacsclient.
Specs: GNU Emacs 27.1, use-package, Windows Subsystem for Linux, X410 window manager.
Additional information: Test times above are for org files (with org packages successfully loaded by the daemon.) Similar differential load times observed for identical text files. The observed behavior is independent of the file order, that is, the first invocation is slow and the subsequent invocations fast regardless of whether opening filename1 then filename2 or vice versa. Overall slowness may be caused by the fact I am running a virtual machine (WSL)
Following phils suggestion, I compared the value of the
features variable after each invocation of emacsclient.
After running emacs --daemon, invoking emacsclient -c without visiting a file loads an empty frame in less than one second. The value the
features variable is quite large, so I defer quoting the full value in this thread. Next, invoking emacsclient -c "file1.org" loads the frame in 8 seconds. The difference between the value of
features between the first invocation without visiting a file and the invocation visiting a file is:
rx org-eldoc face-remap flyspell ispell org-indent ol-eww eww mm-url ol-rmail ol-mhe ol-irc ol-info ol-gnus nnir gnus-sum shr svg dom gnus-group gnus-undo gnus-start gnus-cloud nnimap nnmail mail-source utf7 netrc nnoo gnus-spec gnus-int gnus-range gnus-win gnus nnheader ol-docview doc-view jka-compr image-mode exif ol-bbdb ol-w3m pp cl-print
The third invocation, emacsclient - c "file2.org" loads the frame in less than one second and the value of
features is unchanged from the second invocation.
Based on the change in the value of the
features variable, there appear to be several suspects for the one-time, eight second delay experienced when first visiting a file. The only one I recognize is flyspell, which is configured by use-package to load with hooks to text-mode and org-mode. Is there a way to load these features in the daemon rather than when opening files? The fact that subsequent invocations of emacsclient do not cause this delay suggests they need be loaded only once.