Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Huge memory usage when analysis 9 lines python code #278

Closed
jxww opened this issue Oct 18, 2018 · 5 comments
Closed

Huge memory usage when analysis 9 lines python code #278

jxww opened this issue Oct 18, 2018 · 5 comments
Assignees

Comments

@jxww
Copy link

jxww commented Oct 18, 2018

Hi everyone,

I am writing some python code using vscode with python-language-server extension and just find out Microsoft.Python.LanguageServer.exe eat all of my memory (over 8g) when I open a specific file. I finnally reduced the problematic file to the following 9 lines and the language server still use over 2.6g memory.

Python code:

class A():
    def test(self, test):
        return test
class B():
    def test(self, test):
        return test
class C():
    def test(self, test):
        return test

The interesting thing is that if I remove any of the class/method or change any of the test token in the code, then the language server will run normally with only 100+m memory cost.

My environment is as follow:

  • vscode 1.28.2
  • python extension 2018.9.0 with language server 0.1.42
  • windows 10 pro 64 bit
  • python 3.6

image
image

I think the may be something wrong in code analysis. Anyone can fix it? Thanks very much.

@jakebailey
Copy link
Member

I can reproduce this against both the released version (on my personal machine) and master (on my dev machine). Sometimes I can cut and paste the code a few times to make it go past the ~2.5GB of usage, or even drop down to ~40MB.

I did a memory snapshot when usage is high, and it seems like most of the memory is storing JSON-related objects (Newtonsoft.Json.Linq.Property, JValue, JObject, dicts/arrays of those objects). AFAIK the only place we're using JSON is for RPC.

Actually looking at some of the objects shows that they're cyclic. Maybe they're not getting GC'd properly.

@jakebailey
Copy link
Member

I'll look at this more tomorrow (so it's not midnight), but after following the "path to root" for many of these objects, they all seem to lead up to Actions in StreamJsonRpc which are holding onto JsonRpcMessages with their status set to "RanToCompletion".

@AlexanderSher AlexanderSher self-assigned this Oct 18, 2018
AlexanderSher added a commit to AlexanderSher/python-language-server that referenced this issue Oct 18, 2018
- Fix issue microsoft#109: Reloading modules leaks memory
- Fix issue microsoft#278: Huge memory usage when analysis 9 lines python code
- Some code clean-up
@jakebailey
Copy link
Member

#280 fixes it. Your example now sits at a nice 26MB on my system. 😄

Thanks for providing a concise way to reproduce the issue.

@jxww
Copy link
Author

jxww commented Oct 19, 2018

Thank you for all of your nice and quick response.
I updated my python extension to 2018.9.1(with python language server 0.1.42) just now and still found this problem. Is this fix merged to the new release version?

@MikhailArkhipov
Copy link

@jxww - no. Extension only updates LS with stable releases while this change is less than a day old. The change will be available for insiders build of the extension some time in the next few days. We do not push beta bits to stable releases.

jakebailey pushed a commit to jakebailey/python-language-server that referenced this issue Nov 1, 2019
- Fix issue microsoft#109: Reloading modules leaks memory
- Fix issue microsoft#278: Huge memory usage when analysis 9 lines python code
- Some code clean-up
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants