jorgenschaefer / elpy

Emacs Python Development Environment
GNU General Public License v3.0
1.9k stars 261 forks source link

Very slow-autocompletion on dot #1657

Open rsuhada opened 5 years ago

rsuhada commented 5 years ago

Summary

I'm getting very slow auto-completion results - essentially every complete on dot takes ~5 seconds to display.

e.g. after typying dd.sele it takes 5+ seconds to see the two candidates (dd.select and dd.select_dtypes).

General autocompletion (not after dot) varies - sometimes it is immediate but sometimes takes a few seconds as well.

Update: I've noticed that the RPC process often spikes CPU to 100% and in a longer session, the whole editor starts hanging.

Thank you!

My configuration

OS

Ubuntu 18.04.3 LTS Kernel: 5.0.0-27-generic x86_64 bits: 64

Result of (elpy-config)

Elpy Configuration

Emacs.............: 26.2
Elpy..............: 1.31.0
Virtualenv........: tf-cpu (/home/rxs/anaconda3/envs/tf-cpu)
Interactive Python: python 3.7.3 (/home/rxs/anaconda3/bin/python)
RPC virtualenv....: elpy-rpc-venv (/home/rxs/.virtualenvs/elpy-rpc-venv)
 Python...........: python 3.7.3 (/home/rxs/.virtualenvs/elpy-rpc-venv/bin/python)
 Jedi.............: 0.15.1
 Rope.............: 0.14.0
 Autopep8.........: 1.4.4
 Yapf.............: 0.28.0
 Black............: 19.3b0
Syntax checker....: Not found (flake8)

Elpy configuration in my init.el

(use-package elpy
  ;; usel m-x elpy-config to check/debug pathsA
  :ensure t
  :defer t
  :init
  ;; to get rid of the annoying message
  (add-to-list 'warning-suppress-types '(undo discard-info))
  :config
  (elpy-enable)
  (flymake-mode-off)
  (setq jedi:complete-on-dot t)
  (setq python-indent-offset 4)
  (setq elpy-rpc-backend "jedi")
)
gopar commented 5 years ago

Hey, it looks like you have the jedi.el package installed along side with elpy. Can you try disabling jedi.el when entering a python file? Elpy uses it's own process of jedi, and there's been issues where elpy and jedi give weird behaviours when used together (like the one you observing).

Once you try that can you give an update?

Thanks!

rsuhada commented 5 years ago

Thanks for the pointer:

I did have an old stranded jedi package in my elpy directory. I did not call it any place in my init.el, though. I removed it and completely reinstalled elpy too. Unfortunately the behaviour stays the same... it still spikes the CPU and is very slow.

The config and package versions stayed the same.

Please note that I need to use conda as my python/virtual env, not sure if that is relevant though....

Another hint might be that I think that it really is the completion after the dot that causes the issue. Standard completion is pretty much always fast, my feeling is that the occasional hang-up happens only if I type fast and the process still hangs on the previous dot completion...

When I wait and CPU is not spiking direct completion seems to be always fast.

galaunay commented 5 years ago

I did have an old stranded jedi package in my elpy directory. I did not call it any place in my init.el, though.

I think @gopar was talking about the jedi.el package, that you may need to uninstall with M-x package-delete RET jedi RET.

rsuhada commented 5 years ago

Yes, I understand - there was no jedi.el installed. The issue is still there. Oneway I can get rid off the hang-ups is disabling company-mode in the buffer - but I'd like to have the completion...

galaunay commented 5 years ago

Ok so there may be a problem indeed.

What is the value of elpy-rpc-timeout and elpy-get-info-from-shell in your case ?

Could you try disabling company-mode and running (elpy-rpc-get-completion) with the cursor after a . (like dd. in your example) ? Just to check if the problem comes from company or Elpy.

rsuhada commented 5 years ago

Here are the values: elpy-rpc-timeo is 1 elpy-get-info-from-shell is nil

(elpy-rpc-get-completion) this function doesn't exist. Perhaps you meant something else?

rsuhada commented 5 years ago

I've disabled company-mode after a short while I start getting the CPU spikes... so it seems to be elpy...

galaunay commented 5 years ago

Forgot an "s": (elpy-rpc-get-completions).

There was some issues with jedi spawning a lot of subprocess. does the process eating the CPU look like this ?

/home/some-user/.virtualenvs/elpy-rpc-venv/bin/python -W ignore -m elpy.__main__

Is there a lot of them ?

rsuhada commented 5 years ago

Executing (elpy-rpc-get-completions) gives following error:

Debugger entered--Lisp error: (error "Timeout during RPC call get_completions from backend") signal(error ("Timeout during RPC call get_completions from backend")) error("Timeout during RPC call %s from backend" "get_completions")

The process looks exactly as you write, except I see only one at >90% CPU usage.

galaunay commented 5 years ago

So it may be jedi having trouble parsing your code.

Does it also happen with smaller pieces of code ? like:

class Foo(object):
  def __init__(self, a, b):
    self.a = a
    self.b = b

bar = Foo(4, 5)
bar.   # <-- cursor here

If not, is it possible to have access to the code you are having trouble with ? Or a minimal example generating the issue ?

saideeptiku commented 3 years ago

Forgot an "s": (elpy-rpc-get-completions).

There was some issues with jedi spawning a lot of subprocess. does the process eating the CPU look like this ?

/home/some-user/.virtualenvs/elpy-rpc-venv/bin/python -W ignore -m elpy.__main__

Is there a lot of them ?

@galaunay I have been having this issue, when elpy.main runs when I try to autocomplete, and I have Jedi. I believe Jedi starts building indexes often. SO, if I have imported large packages like numpy it takes forever and uses CPU heavily. It also leads to emacs hanging. what do you suggest?