riscy / shx-for-emacs

An Emacs shell-mode (and comint-mode) extension that enables displaying small plots and graphics and lets users write shell commands in Emacs Lisp.
GNU General Public License v3.0
224 stars 11 forks source link

:ssh input lag with company mode #29

Open NicholasBHubbard opened 3 years ago

NicholasBHubbard commented 3 years ago

If I use company-mode with :ssh my typing becomes delayed until the company completion frame pops up. Normally I have company set to pop up in 0.1 seconds but it takes about 5 seconds while using :ssh. When I am typing no text appears in this 5 second time frame.

I do not have any problems with company and shx when I am not using :ssh.

I do not have the same problem with auto-complete-mode.

If I turn off shx mode and use regular ssh from shell-mode, I do not have any delay and company works fine.

my company settings are very basic, this is all I have changed:

(setq company-idle-delay 0.1
      company-minimum-prefix-length 3
      company-show-numbers t)
riscy commented 3 years ago

Thanks very much for reporting this -- I'm not entirely sure this has an easy fix, since some autocomplete/autodoc utilities iterate over the contents of lots of files to create their outputs without any kind of caching.

A couple of other examples that have impacted me similarly are eldoc-mode and anaconda-eldoc-mode, which made the editing of python/elisp files over tramp impossible on a faraway host with a slow filesystem. Part of my current python-mode-hook is to disable the feature entirely:

(and  ; eldoc-mode has _brutal_ perf over tramp:
      (file-remote-p default-directory)
      (fboundp 'turn-off-anaconda-eldoc-mode)
      (run-with-idle-timer 0.2 nil 'turn-off-anaconda-eldoc-mode))

which I realize isn't a solution to your problem.

I think this is a good issue to have open and on my radar because there might be some situations where shx can potentially mitigate this. company-mode might be one of them, but it's a tricky issue.

melodrom commented 3 years ago

I noticed the input lag with company as well! The issue is that I dont get any TAB-Completions when turning it off, which makes it almost unusable for me. Any idea what can be done about at least getting the normal bash tab completions?

melodrom commented 3 years ago

hmm, tab completions for paths actually seems to work but command completion doesnt

riscy commented 3 years ago

Any idea what can be done about at least getting the normal bash tab completions?

I had a look at company's code and I'd suggest experimenting with the variable company-backends. You could start off by setting it to the empty list, and then slowly add completion engines until you find the one that's slowing you down.

$ :eval (setq-local company-backends nil)

I suspect the completion engines that are causing the most slowdown (but are also unfortunately probably among the most useful) are company-files and company-capf, but maybe you can confirm? Without really understanding company, I wonder if their behavior has some overlap. Some examples that might get you started:

$ :ev (setq-local company-backends '(company-capf))
$ :ev (setq-local company-backends '(company-files))
$ :ev (setq-local company-backends '(company-files company-capf))
NicholasBHubbard commented 3 years ago

I was able to narrow down the issue to company-capf. If I remove this backend from shx-mode then everything works fine.

NicholasBHubbard commented 3 years ago

I stumbled into a perfect workaround for this problem if you use bash (though I haven't looked into why it works). If you use the emacs-bash-completion package with the (setq bash-completion-use-separate-processes t) option the stuttering problem over :ssh totally disappears and you get even better completion than you would get otherwise.

My use-package config for reference:

(use-package bash-completion
  :custom
  (bash-completion-use-separate-processes t)
  :config
  (bash-completion-setup))