reddit / emacs
Feeling lag in typing - where to troubleshoot?
deafpolygon · 2022-12-20 10:18
I'm a fast typist, and I can feel there is a lag in typing and responsiveness in Emacs. I know it's probably a package or something I'm doing that's causing it, but where do start tracking this down? I don't mind it when I'm writing code, but it's a bit distracting when I'm typing prose or a journal.
lycopodiopsida · 2022-12-20 10:30
These tips are written for doom emacs, but are helpful in general and a good starting point: https://discourse.doomemacs.org/t/why-is-emacs-doom-slow/83/3
Tohiko · 2022-12-20 10:52
90% of the time, I found smartparen to be the culprit.
churchzebra · 2022-12-20 10:54
close all minor modes, then enable one by one, check whether lag still exists, find which one cause the problem.
deafpolygon · 2022-12-20 10:55
I am running multiple 4k displays, as well as writing prose that are over 400 characters long per "line", on top of using Wayland (Sway). Is there any hope for me?
(Btw, emacs -nw is quick and flawless).
lycopodiopsida · 2022-12-20 11:08
Yes - in vim ;)
I think performance with long lines should improve in emacs@29. Maybe worth a shot already?
deafpolygon · 2022-12-20 11:12
I'm not opposed to Vim. I use it already.. but I was hoping for an editor with some bells & whistle like linking, taking advantage of org-mode, embedded images, different font sizes, etc. But maybe it wasn't meant to be. :) I'll keep looking. Maybe try emacs-29 out.
lycopodiopsida · 2022-12-20 11:13
There is also the built-in profiler, you could enable it, type for some time an look in the report where time was spent: https://ianyepan.github.io/posts/emacs-profiling/
deafpolygon · 2022-12-20 11:17
Over 80% of the time spent on "redisplay_internal". 11% of the time spent on "..." (not sure what that is).
Edit: ah, tabbing expands stuff with a + at the front.
12965 83% - redisplay_internal (C function)
12877 83% - jit-lock-function
12875 83% - jit-lock-fontify-now
12873 83% - jit-lock--run-functions
12873 83% - #<compiled 0x19a290f3faa3fe7d>
12841 83% - font-lock-fontify-region
12841 83% - font-lock-default-fontify-region
12587 81% - font-lock-fontify-keywords-region
12564 81% org-do-latex-and-related
Org-do-latex-and-related?
lycopodiopsida · 2022-12-20 11:21
Yes, I think one should have realistic expectations - running a lisp interpreter in the background and triggering a bunch of elisp functions on every keypress has its price. Additionally, rendering is a long-known weak-point of emacs and the tendency to install a shitload of plugins also does not help.
lycopodiopsida · 2022-12-20 11:28
> org-do-latex-and-related
Seems so. There is a thread on SO: https://stackoverflow.com/questions/59990932/slow-cursor-movement-in-large-org-mode-file-and-the-org-do-latex-and-related-f
can you try to set (setq org-highlight-latex-and-related nil) ?
mickeyp · 2022-12-20 11:33
400-character lines does not slow down Emacs. The issue is clearly elsewhere.
deafpolygon · 2022-12-20 11:49
There's a definite improvement, but still there is some lag present. I guess the rest of that is down to the other issues. Ran the profiler, 52% is now "..." which contains only "Automatic GC".
lycopodiopsida · 2022-12-20 11:58
I've seen some threads with obscure gc-tuning, but it was in pre-emacs 27 times and mostly related to lsp performance problems. I doubt that it will be of any help here and even that it was of any help back then.
I would start with commenting out the plugins in groups to narrow the suspect and checking afterwards. As annoying as it is. If -nw is running quick, it is either one of them, or something wrong in the config.
tgrnh · 2022-12-20 12:07
I started my Emacs journey with v27 on an old Laptop and ran into this problem everytime when I wanted to "beautify" the appearance. When I went back to a simple Mode Line, it felt like a new device. But too much different fonts with variable-pitch etc. in big org-mode files also slowed things down a lot. Newer versions seem much faster, but I didn't test fancy Mode lines again, also I can toggle my "Beauty Mode" for reference/comparison.
unhammer · 2022-12-20 13:48
for me it was rich-minority (via smart-mode-line) + flycheck.
If it's fast with `emacs -Q` then it's most likely whatever third party packages you're using.
ntrysii · 2022-12-20 14:38
if you're using `key-chord` try running without it and see if anything changes.
natostanco · 2022-12-20 16:04
when gc starts to be the bottleneck, restart emacs. That's pretty much the only solution I found, I do it at least once or twice per day
redblobgames · 2022-12-20 16:14
It's quite frustrating. I couldn't find a great way to track things down so I ended up removing things until it got fast again.
For me it was a fancy mode line I was using. I switched to the default mode line and things got faster. And then I added mode line features back one by one and removed the elements that slowed me down.
tdrhq · 2022-12-20 16:15
Do you have long lines in your buffer? I find font-lock mode to slow down buffers with long lines. Disable font-lock on the buffer and see if it fixes things.
deaddyfreddy · 2022-12-20 18:53
The default GC settings are pretty generic, you can take a look at GCMH package which takes care of setting hook/thresholds etc.
shintak · 2022-12-21 07:05
`M-x profiler-start` and choose cpu+memory. Type for a little bit and then `M-x profiler-report`. It will show which function take how much cpu/memory.
NotFromSkane · 2022-12-21 19:43
When `-nw` runs flawlessly it's not the lisp interpreter that's the issue. It's just the renderer.