If I remove my .emacs
file and .emacs.d
folder, just to be sure that what I observe is not caused by an issue in my personal configuration, and I invoke
emacs foo.txt
the emacs windows opens, stays blank for at least 5 seconds with 'Lisp Interaction ElDoc'
written in the center of the bar at bottom where the major mode is usually indicated. Then (that is after several seconds), the window gets separated vertically into two parts with the splash screen on the bottom part and the document foo.txt on the top part, and the 'Lisp Interaction ElDoc' gets replaced by '(Text)' as expected.
If I subsequently close the document and immediately invoke
emacs foo.txt
again, then I directly get the final window (separated in two, with the splash screen and everything) without being stuck in the first state for seconds.
But, if I close the document and wait for some amount of time (a minute or so), and then invoke
emacs foo.txt
again, the emacs window opens, it stays blank for at least 5 seconds with '(Fundamental)' written in the center of the bar at bottom, and the message 'Loading /usr/share/emacs/site-lisp/site-start.d/rpmdev-init.el... done' (which is the last file loaded from /usr/share/emacs/site-lisp/site-start.d/ if you wonder). Then, the file pops up, together with the splash screen, etc.
The content of *Messages*
gives me no information whatsoever on what emacs can be trying to do between finishing loading rpmdev-init.el
and displaying the splash screen (with the message "For information about GNU Emacs and the GNU system, type C-h C-a."). Here is the content of *Messages*
:
Loading /usr/share/emacs/site-lisp/site-start.d/auctex.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/autoconf-init.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/clang-format.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/clang-include-fixer.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/clang-rename.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/cmake-init.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/desktop-entry-mode-init.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/mercurial-site-start.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/pg-init.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/preview-latex.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/protobuf-init.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/rpmdev-init.el (source)...done
For information about GNU Emacs and the GNU system, type C-h C-a.
This behavior (having sometimes to wait for seconds before being able to edit the file) is annoying. I know that I could start emacs as a server to avoid reloading everything everytime I want to open an emacs window, but nevertheless, I would like to understand what is happening behind the scene, because this seems to be the trace of something anormal. So my question is: does anyone has an idea of what causes emacs to have this behavior? Or any clue on how to proceed to figure it out?
I tried with emacs -q
and emacs -Q
and observe the same phenomenon. I am using emacs 27.2 on Fedora 34.
Edit: similar questions have very often been posted on StackOverflow (and much more on SO than on any other StackExchange website, as far as I can tell). For instance:
- The closest question I found to my issue is here.
- Another very close one is here (or here which is merely a duplicate).
- That one.
- That one and that one seemed to be irrelevant to my case.
- etc.
The usual suspects are a bad configuration (excluded here because the issue happens even with -Q
) or a bad hostname configuration (should be fixed on modern versions of emacs as far as I understood, and, anyway, my hostname is correctly configured).
I am still trying to compare the traces emacs_slow.strace
and emacs_fast.strace
obtained as the result of
strace -tt -o emacs_slow.strace emacs foo.txt -eval '(kill-emacs)' && \
strace -tt -o emacs_fast.strace emacs foo.txt -eval '(kill-emacs)'
They are both about 21k lines and fairly similar. If someone has a clue on what to check specifically for, advice are welcome.