[Bug]: Python parse cache holds up to 2,048 trees and drives update peak RAM to 1.4-2.5 GB (django never even hits it)
Pre-flight checks
- [x] I have checked the Troubleshooting section in the README
What happened?
graphify update / extract peaks at 1.4-2.5 GB on mid-size Python repos, and most of it is one cache: _parse_python_tree_cached in graphify/extractors/resolution.py, an lru_cache(maxsize=2048) of (source, root_node) added in #3502.
- It keeps up to 2,048 parsed trees alive. py-tree-sitter caches each node's
.childrenlist, so walking a cached tree once keeps a PythonNodeobject for every node in it. tracemalloc on django: about 775 MB still live after_augment_symbol_resolution_edgesreturns. - #5063 clears the cache after
extract(), but the peak happens before that, while both resolution passes run. - On a repo with more than 2,048
.pyfiles (django: 2,923) the second pass walks in the same order as the first, so it never hits the cache at all.
Measured on Linux, 4 cores, Python 3.13. Time is the fastest of 3 cold runs.
| repo (.py files) | peak RSS on v8 |
|---|---|
| sympy (1,606) | 2,541 MB |
| pandas (1,552) | 2,066 MB |
| django (2,943) | 1,412 MB |
Steps to reproduce
git clone --depth 1 https://github.com/django/django && cd django
GRAPHIFY_MAX_WORKERS=1 /usr/bin/time -v graphify extract . --code-only --out /tmp/o
"Maximum resident set size" is about 1.4 GB.
Error output or graph output
No error; high peak memory. With the cache replaced by a plain parse (graph.json byte-identical), django peaks at 425 MB.
Graphify version
0.9.106 (v8 at 35d1d203)
Operating System
Linux (measured), also Windows
Python Version
3.13
Installation Method
uv tool install (recommended)
Thanks for opening this issue, @rohit-jsfreaky. A maintainer will take a look soon.
If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.
To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.