Emacs cursor navigation and insertion is really slow
Hello,
Navigating and editing buffers is really slow in c-mode, python-mode and probably others. It's become really frustrating. Is there a way I can profile navigation and editing only?
My primary suspect is post-command-hook, which is set to the following value in a c-mode buffer with about 800 lines of code, I'd like to find out which of those is the slowest.
(linum-schedule whitespace-post-command-hook
flycheck-hide-error-buffer flycheck-display-error-at-point-soon
flycheck-error-list-highlight-errors
flycheck-error-list-update-source
flycheck-perform-deferred-syntax-check company-post-command t)
The currently enabled minor modes are:
Auto-Composition Auto-Compression Auto-Encryption Column-Number
Company Dynamic-Completion Electric-Indent File-Name-Shadow
Flycheck Flycheck-Pos-Tip Font-Lock Global-Font-Lock Gud-Tooltip
Helm-Gtags Line-Number Linum Menu-Bar Mouse-Wheel Recentf
Savehist Shell-Dirtrack Show-Paren Size-Indication Tooltip
Transient-Mark Whitespace
And here is my emacs init file.
emacs-version: GNU Emacs 24.5.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.20.6) of 2016-06-04 on juergen, using the gtk3 interface.
Thank you.
EDIT: Formatting.
EDIT 2: More formatting.
EDIT 3: Typo.
Update:
I ran profiler-start and navigated around, then profiler-report and here is the output.
- timer-event-handler 2645 53%
- byte-code 2629 53%
- apply 2629 53%
- linum-update-current 2622 53%
- linum-update 2618 53%
- mapc 2610 53%
- linum-update-window 2551 51%
- funcall 64 1%
#<compiled 0x7f475f> 58 1%
line-number-at-pos 19 0%
- show-paren-function 3 0%
show-paren--default 3 0%
+ timer-activate-when-idle 7 0%
cancel-timer-internal 3 0%
- redisplay_internal (C function) 1499 30%
- linum-after-scroll 1368 27%
- linum-update 1362 27%
+ mapc 1360 27%
get-buffer-window-list 2 0%
+ eval 66 1%
+ jit-lock-function 54 1%
+ #<compiled 0x4132e5> 6 0%
file-remote-p 5 0%
+ command-execute 477 9%
+ ... 219 4%
+ linum-schedule 31 0%
+ company-post-command 12 0%
+ completion-before-command 9 0%
+ flycheck-display-error-at-point-soon 7 0%
flycheck-hide-error-buffer 5 0%
company-pre-command 3 0%
flycheck-pos-tip-hide-messages 2 0%
So I disabled linum-mode and things are smoother but sometimes still sluggish especially when the buffer needs to move/scroll.
At this point I'm not sure how to fix linum-mode (linum-after-scroll, linum-update).
Another update: here is the profiler output without linum-mode:
- redisplay_internal (C function) 1908 42%
- jit-lock-function 1521 33%
- jit-lock-fontify-now 1518 33%
- funcall 1507 33%
+ #<compiled 0xcb4723> 1502 33%
+ #<compiled 0xd2d64b> 5 0%
- eval 297 6%
flycheck-mode-line-status-text 160 3%
if 76 1%
mode-line-eol-desc 7 0%
file-remote-p 41 0%
+ #<compiled 0x4132e5> 38 0%
- command-execute 1435 31%
- call-interactively 1424 31%
- previous-line 723 15%
+ funcall 714 15%
+ called-interactively-p 6 0%
+ next-line 482 10%
+ byte-code 103 2%
+ execute-extended-command 45 0%
+ newline 19 0%
+ save-buffer 14 0%
+ c-electric-backspace 11 0%
+ scroll-up-command 7 0%
+ self-insert-command 6 0%
+ completion-separator-self-insert-autofilling 1 0%
+ timer-event-handler 551 12%
+ ... 441 9%
+ flycheck-handle-signal 40 0%
+ company-post-command 22 0%
+ completion-before-command 21 0%
+ flycheck-display-error-at-point-soon 21 0%
+ linum-schedule 15 0%
x-set-selection 15 0%
+ whitespace-post-command-hook 13 0%
+ company-pre-command 12 0%
+ flycheck-hide-error-buffer 10 0%
internal-timer-start-idle 7 0%
+ flycheck-pos-tip-hide-messages 4 0%
tooltip-hide 3 0%
+ flycheck-perform-deferred-syntax-check 3 0%
+ deactivate-mark 3 0%
+ #<compiled 0xcbb30b> 1 0%
Posted Sep 12, 2016, 10:15 AM UTC · edited
If line numbers are important to you, you could try
nlinum-modeinstead oflinum-mode(available from GNU ELPA). It doesn't update as often so it might be better.As for the slowness without
linum-mode, what do you see when you open up thefuncallunderprevious-line:Is it just some compiled code or do you get further functions? Same thing with
next-line. Those two and jit-lock seem to be the ones where most time is spent. Especially for(previous|next)-lineI find that somewhat surprising.Thanks! The problem still persists to a lesser extent, but still noticeable, with
linum-modedisabled. I'm currently looking into font-lock.