-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clear pylint's LRU caches when using --clear-cache-post-run
#8361
Comments
Reproduction code from the vscode issue: |
I'm in favour of closing this. Creating an object with a size of 4GB will obviously cause large memory usage, the issue in VS Code shows how the cache can be fully cleared after each run. |
I think it depends, do you encounter the problem on |
@Pierre-Sassoulas I am experiencing this issue on |
|
Let's keep this open for some investigation, with the understanding we may or may not identify a follow-up action. IIUC Python doesn't always release memory back to the OS even after manual garbage collection. |
This is just a one-line minimal reproduction. I encounter this issue daily working with regular Python files and Jupyter notebooks in VS Code. I constantly monitor how much memory Python processes use on my machine for other reasons, and I noticed this. I suspect the issue is much more widespread, but people don't notice it, in my case it leaks around 1 GB per hour of VS Code usage. The most I've seen is 6 GB, but I guess it depends on what code you're editing. |
Look like there's something wrong with the pylint server like / daemon. Maybe it's the way we handle cache possibly in astroid. This will require investigation, I suggest to turn it off and on again from time to time if server mode is worth it, or to try running it without server mode otherwise, while we investigate the issue. |
I don't think this is the issue here. Python did indeed had this problem a long time ago (in the 2.x era), but it was mostly fixed. Deleting the object promptly releases the memory on the same machine I encounter this issue: x = b"a" * 4_000_000_000
del x |
@DanielNoord identified the reason astroid is leaking memory: there's a reference cycle from child nodes back to their parents. Probably a classic use case for Thanks for the report; closing as duplicate of pylint-dev/astroid#1780 |
Although there are astroid updates needed, there are also pylint updates I just identified, so I'll reopen this to track that work. Apologies for the churn. We need to introduce a similar mechanism as astroid has for clearing the LRU caches for any calls to pylint with We can then call it here. For the sample code from OP, the changes I'm suggesting together with pylint-dev/astroid#2043 vastly improved memory allocation. |
--clear-cache-post-run
Seems like it's not fixed by what was put in 2.17.1 alone: microsoft/vscode-pylint#280 (comment) |
Yes - I was hoping that pylint-dev/astroid#1780 would still have some things left to be released, but I understand that pylint-dev/astroid#2043 should be in astroid 2.15.0 already, and that is what I have been testing with. Each time I save a Python file kick off a And the extension clearly reports using 2.17.1/2.15.0:
|
Indeed, I wouldn't retest this until that's in a released version of astroid.
I'd argue for closing this issue since we re-scoped it to "clear pylint's LRU caches when using --clear-cache-post-run", not fix all of astroid's leaks. |
@jacobtylerwalls oh, are you saying that what you reported in pylint-dev/astroid#1780 (comment) goes beyond #2043, so there is stuff waiting to be released that might fix the most major issue (except for dicts)? That would be cool, but I am a bit worried by milestone 3.0 mentioned in pylint-dev/astroid#1780 (comment) ;) |
We have a lot to do for the pylint 3.0.0 release but most deprecation are already handled and we're going to release alphas and beta. We will release the astroid cache change soon after the work is completed in astorid. Regarding astroid 3.0 we can be a little less drastic with the deprecations because we're the main consumer of astroid (98% of astroid users, use astroid through pylint). |
Thanks for encouraging me to look closer :-) Looks like pylint-dev/astroid#1780 (comment) already is achieved in 2.15.0. EDIT: but since one reference is all that takes to leak, I don't know if the current state of things is enough to solve the bulk of your day-to-day issue. What VS Code extension are you using? From this comment, I see 2023.2.0 is the minimum version. From your log, this invocation is missing the
|
Aha! Yes, adding "pylint.args": [
"--clear-cache-post-run",
], fixes the issue. So it seems 2.17.1/2.15.0 has all that's needed, thank you :) I am using the most recent release version of the extension (2023.4.0), same thing with the latest prerelease (v2023.5.10801010). I'll post more details on why the flag is missing in microsoft/vscode-pylint#280. |
@jacobtylerwalls Does that mean congratulations are in order? Well done on fixing this issue! |
That's amazing @jacobtylerwalls ! I has given up on memory leaks, but your success with it make me hopeful about astroid's future performances too 😄 |
Bug description
Many times a day, a

python.exe
process launched byms-python.pylint
takes up several GB of memory, and is uneager to release it. This has been reported at microsoft/vscode-pylint#280 with fairly straightforward reproduction steps. This is the result for me:microsoft/vscode-pylint#280 credibly (for me) claims this should be reported here, so that's what I do.
Configuration
Command used
Pylint output
Expected behavior
Irrelevant
Pylint version
OS / Environment
Windows 10 21H2
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: