palantir / python-language-server

An implementation of the Language Server Protocol for Python
MIT License
2.6k stars 282 forks source link

Profile completion #826

Open ANtlord opened 4 years ago

ANtlord commented 4 years ago

Pull request for https://github.com/palantir/python-language-server/issues/823

I've done a little investigation so I can say that Completion.get_signatures() and Completion.docstring() slow down performance about 5 times. The results of the functions are not seen in completions for NeoVim/Vim at least so calling the functions is overhead for the case.

I dump time ranges in files /tmp/pyls_completions.prof for pyls_completions method and /tmp/PythonLanguageServer.completions.prof for completions method of PythonLanguageServer class.

Here are the results of the investigation:

==> pyls_completions.prof.fast <==
pyls_completions total 0:00:00.724521 format_profile_ranges defaultdict(<class 'datetime.timedelta'>, {'documentation': datetime.timedelta(microseconds=324), 'update': datetime.timedelta(microseconds=75766), 'total': datetime.timedelta(microseconds=76090)})
pyls_completions total 0:00:00.165487 format_profile_ranges defaultdict(<class 'datetime.timedelta'>, {'documentation': datetime.timedelta(microseconds=321), 'update': datetime.timedelta(microseconds=23167), 'total': datetime.timedelta(microseconds=23488)})
pyls_completions total 0:00:00.177044 format_profile_ranges defaultdict(<class 'datetime.timedelta'>, {'documentation': datetime.timedelta(microseconds=297), 'update': datetime.timedelta(microseconds=23520), 'total': datetime.timedelta(microseconds=23817)})

==> pyls_completions.prof.slow <==
pyls_completions total 0:00:01.708528 format_profile_ranges defaultdict(<class 'datetime.timedelta'>, {'documentation': datetime.timedelta(microseconds=626150), 'update': datetime.timedelta(microseconds=426714), 'total': datetime.timedelta(seconds=1, microseconds=52864)})
pyls_completions total 0:00:01.132067 format_profile_ranges defaultdict(<class 'datetime.timedelta'>, {'documentation': datetime.timedelta(microseconds=546148), 'update': datetime.timedelta(microseconds=432481), 'total': datetime.timedelta(microseconds=978629)})
pyls_completions total 0:00:01.099432 format_profile_ranges defaultdict(<class 'datetime.timedelta'>, {'documentation': datetime.timedelta(microseconds=535644), 'update': datetime.timedelta(microseconds=409444), 'total': datetime.timedelta(microseconds=945088)})
pyls_completions total 0:00:01.216887 format_profile_ranges defaultdict(<class 'datetime.timedelta'>, {'documentation': datetime.timedelta(microseconds=632716), 'update': datetime.timedelta(microseconds=429011), 'total': datetime.timedelta(seconds=1, microseconds=61727)})

==> PythonLanguageServer.completions.prof.fast <==
completions 0:00:00.725947
completions 0:00:00.166862
completions 0:00:00.178388

==> PythonLanguageServer.completions.prof.slow <==
completions 0:00:01.710710
completions 0:00:01.134438
completions 0:00:01.101723
completions 0:00:01.218994

The .fast reports are done with commit a0d32bb; the .slow reports are done with 21c484e.

The first one doesn't get signatures, documentation and labels for completions. Code in the latter commit differs from version from develop branch but does the same. As wrote the data is not required to get completions but it slows down performance 5 times after the first call. The first call is slower only 2 times because Jedi use sources instead of its internal cache. Tested script consists of import os; os..

I don't have certain suggestions. The only idea I have is introducing new settings avoids getting documentation and pretty labels.

palantirtech commented 4 years ago

Thanks for your interest in palantir/python-language-server, @ANtlord! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

astier commented 3 years ago

You need to sign a two page long license agreement full of corporate gibberish just to make a PR? bruh... Can I find somewhere an explanation or a statement why this is necessary? I thought pyls is MIT Licensed.

idoktz commented 3 years ago

Huge improvement for large projects. I hope a PR with better defaults (without docs & labels) as suggested will get merged soon.