srusskih / SublimeJEDI

awesome Python autocompletion with SublimeText
MIT License
938 stars 109 forks source link

Jedi 0.13+ slow over SSHFS, throws error after typing a single character #262

Closed RicherMans closed 6 years ago

RicherMans commented 6 years ago

Hey there, I personally only work via remote on a server. The remote drive is located nearby, thus usual pings or general access over sshfs is pretty fast. The old version 0.12 didn't have much lag, but the newer versions since 0.13 all lag after typing a single character, no matter which one. From time to time it also throws the error:

Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 685, in on_query_completions
    res = vel.on_query_completions(prefix, locations)
  File "/home/richman/.config/sublime-text-3/Packages/Jedi - Python autocompletion/sublime_jedi/completion.py", line 154, in on_query_completions
    location=locations[0]
  File "/home/richman/.config/sublime-text-3/Packages/Jedi - Python autocompletion/sublime_jedi/daemon.py", line 83, in ask_daemon_with_timeout
    return request.result(timeout=timeout)
  File "./python3.3/concurrent/futures/_base.py", line 403, in result
concurrent.futures._base.TimeoutError

Also, autocompletion is delayed during typing. e.g., if one types print( , after some seconds the string gets completed with value even though one might already wrote something. It's an annoying little bug.

Is there any good recommendation besides settings up remote python executeables?

srusskih commented 6 years ago

with print( is intersting one, I cannot reproduce it

project config with python3.6 venv

{
    "settings": {
        "python_virtualenv": "/Users/sr/.virtualenvs/platform"
    }
}

jul-26-2018 11-11-43

RicherMans commented 6 years ago

So when opening local files it does not appear to be a big problem. But when I open a file in a sshfs directory, jedi becomes noticeably slower. I personally don't understand why that is, since I would expect that jedi still searches for my local packages for autocompletetion, therefore does not need to wait for the file on theserver.

Here is an example:

remote

I type as fast as I can in that example, but it always stucks / the autocomplete of most functions is quite delayed

srusskih commented 6 years ago

ok, I got. Lets try to measure the performance. I think we should use "jedi" lib for this, without ST3.

Could you please do next:

  1. create a new virtualenv (sublime has own interpreter, so it works as virtualenv)
  2. activate the virtualenv
  3. install jedi in the virtualenv; ex. pip install jedi
  4. create a python script, that should print print() params
    
    import sys

import jedi from jedi.api import environment

source = ''' import numpy as np print('''

def comp(): python_interpreter = sys.argv[1] env = environment.Environment( environment._get_python_prefix(python_interpreter), python_interpreter)

script = jedi.Script(source, 3, len('print('), '', environment=env)
return script.call_signatures()[0].params

print(list(comp()))



4.  run `time python path/to/test_script.py <path to yours project interpreter>`, where
_<path to yours project interpreter>_ is a path to interpreter that you used in SublimeJedi settings.

And please share the results. 

Thanks!
RicherMans commented 6 years ago

Hey @srusskih , I done the requested trials. When running the script from a local place e.g., ~/test_script.py, I get:

[<Definition param value>, <Definition param ...>, <Definition param sep>, <Definition param end>, <Definition param file>, <Definition param flush>]

real    0m0.524s
user    0m0.310s
sys     0m0.037s

However, when putting the script to a remote server, over sshfs, I get:

[<Definition param value>, <Definition param ...>, <Definition param sep>, <Definition param end>, <Definition param file>, <Definition param flush>]

real    0m1.936s
user    0m0.326s
sys     0m0.055s

But still I dont think that a difference in time of 0.5s to 2s matters that much. In sublime it feels rather than ~2-5 seconds delay, on top of that it hangs during the execution.

srusskih commented 6 years ago

yeah, my non perfect implementation (and sublime) gives and overhead :(

have couple ideas, but not sure, if it would works:

  1. something like throttling for completion (I think and hope ST have some throttling and do not call completion after each typed character) - to reduce a completion queue
  2. check a cursor position after completion to avoid useless completions, like that one with print showed by @RicherMans
  3. add completion timeout parameter to manage expectations
  4. show a tooltip instead of parameter completion
RicherMans commented 6 years ago

Hey @srusskih Thanks for the suggestions. I tried:

  1. Even disabling auto_complete in the config does not help :(
  2. That could work, but I want to have the completion after the dot. Its currently always hanging for ~ 3 seconds when I press the dot button. And I press that button a lot. 3.Modified auto_complete_delay in the config to some very high value (e.g. 3s), which prevents the future errors, but still is pretty laggy 4.That works

Overall, thanks for your efforts!

srusskih commented 6 years ago

@RicherMans thanks for reporting (: