microsoft/python-language-server

Analysing in background causes memory leak

IzakMarais opened this issue ยท 8 comments

After the most recent upgrade to the Python extention for VSCode, it grinds my laptop to a halt by consuming all the memory.

Extention information

Name: Python
Id: ms-python.python
Version: 2019.3.6139
Publisher: Microsoft

VSCode version

Version: 1.32.3 (user setup)
Commit: a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4
Date: 2019-03-14T23:43:35.476Z
Electron: 3.1.6
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 10.0.14393

Some images

Capture

Note the Memory usage in Task Manager. This just continues growing rather quickly until it consumes all the available RAM on my laptop (25Gb) within 10 minutes or so.

I don't know which 7000 files it is analyzing, the currently open folder itself is tiny.

I get a similar thing on Linux. For me it maxes out one core for several minutes, and grows to analysing ~4,800 items "in background". I don't get the same memory leak though (it makes out at ~5Gb), and after 5-10 minutes it somehow completes, the number of items to analyse drops rapidly and eventually things return to normal.

This happens whenever I open a Python file, regardless of workspace or folder.

Likewise on macOS... CPU usage off the charts, nearly melted my macbook trying to analyze an ever-growing list of thousands of items... renders Code with Python unusable... only experienced this after latest Language Server update...

Screenshot 2019-03-27 at 16 29 24

Screenshot 2019-03-27 at 16 39 37

Screenshot 2019-03-27 at 16 28 08

Opening a file still brings up import chain so dependencies are looked into. Yes, the memory is eventually released. @martinjohndyer, @commodityAI - could you give some information on what libraries you are using and if project is open source, could you please point to the GH for cloning. Thanks.

Thanks @MikhailArkhipov. Yes it is definitely due to dependencies.

A simple file that contains import astropy (https://github.com/astropy/astropy) and nothing else opened in VSCode peaks "Analyzing in background" at ~4700 items and takes minutes to finish. Just import numpy (https://github.com/numpy/numpy) peaks at ~1500 and takes ~10 seconds.

Is there any further logging that would be useful? I assume it's cumulative, i.e. because Astropy imports Numpy a lot that adds to the time. Is there not any way to cache whatever it's doing so it doesn't have to be rerun every time a new VSCode window is opened?

@MikhailArkhipov sorry can't offer code examples, but for further info I left the same code running on an iMac last night.. went on for 3+ hours with the list of items only growing (got upto 10k+), mem usage reached a whopping 100GB and CPU many times over 100%... I'm only using vanilla python libs (pandas, numpy, flask, jupyter and the likes), nothing exotic... this does not seem a case of working through all the dependencies, but rather an uncontrolled memory leak

For anyone experiencing this problem, a temporary workaround mentioned here microsoft/vscode-python#4986 (comment) is to use the jedi Language server instead.

I'm going to close this in favor of the more active #832.

Using Jedi will be OK