Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
perf(health): release each file's dataflow parse after it is evaluated (#2870)
Raghav Chamadiyac62945e9121a
diff --git a/packages/core/src/repowise/core/analysis/health/dataflow/facts.py b/packages/core/src/repowise/core/analysis/health/dataflow/facts.pyindex dcb813208..a684cf8c4 100644--- a/packages/core/src/repowise/core/analysis/health/dataflow/facts.py+++ b/packages/core/src/repowise/core/analysis/health/dataflow/facts.py@@ -395,3 +395,9 @@ class FileDataflowCache:fd = FileDataflow(abs_path, language, read_source=self._read_source)self._by_path[abs_path] = fdreturn fd++ def release(self, abs_path: str) -> None:+ """Drop a file's entry (its source, tree and analyses) once no later+ consumer in the pass will ask for it, so a repository-wide pass holds+ one file's parse at a time instead of every file it touched."""+ self._by_path.pop(abs_path, None)diff --git a/packages/core/src/repowise/core/analysis/health/engine.py b/packages/core/src/repowise/core/analysis/health/engine.pyindex ffd65a82d..2d3fb8029 100644--- a/packages/core/src/repowise/core/analysis/health/engine.py+++ b/packages/core/src/repowise/core/analysis/health/engine.py@@ -982,6 +982,8 @@ class HealthAnalyzer:methods_by_file=methods_by_file,dataflow_cache=dataflow_cache,)+ # Every dataflow consumer has read this file by now.+ dataflow_cache.release(pf.file_info.abs_path)metrics.append(file_metric)findings.extend(file_findings)suggestions.extend(file_suggestions)@@ -1192,6 +1194,8 @@ class HealthAnalyzer:methods_by_file=methods_by_file,dataflow_cache=dataflow_cache,)+ # Every dataflow consumer has read this file by now.+ dataflow_cache.release(pf.file_info.abs_path)metrics.append(file_metric)findings.extend(file_findings)suggestions.extend(file_suggestions)diff --git a/tests/unit/health/test_dataflow_facts.py b/tests/unit/health/test_dataflow_facts.pyindex b8a086124..dba8a8a9b 100644--- a/tests/unit/health/test_dataflow_facts.py+++ b/tests/unit/health/test_dataflow_facts.py@@ -254,3 +254,49 @@ def test_cache_construction_does_not_touch_the_file(tmp_path: Path):# Nothing read or parsed yet; a consumer call on a missing file is silent.assert fd.flagged_analyses() == []assert fd.analyses_covering({1}) == []+++def test_release_drops_the_entry_and_get_rebuilds_it(tmp_path: Path):+ cache = FileDataflowCache()+ path = str(tmp_path / "a.py")+ first = cache.get(path, "python")+ assert cache.get(path, "python") is first+ cache.release(path)+ cache.release(path) # releasing an absent entry is a no-op+ assert cache.get(path, "python") is not first++[email protected]("use_async", [False, True])+def test_health_pass_releases_each_file_after_evaluating_it(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, use_async: bool+):+ """A repository-wide pass must not hold every file's parse until it ends."""+ import asyncio++ from repowise.core.analysis.health import HealthAnalyzer+ from repowise.core.ingestion import ASTParser, FileTraverser, GraphBuilder++ _require_python()+ for i in range(3):+ (tmp_path / f"m{i}.py").write_text(f"def f{i}(x):\n return x\n", encoding="utf-8")+ parser, gb, parsed = ASTParser(), GraphBuilder(), []+ for fi in FileTraverser(tmp_path).traverse():+ pf = parser.parse_file(fi, Path(fi.abs_path).read_bytes())+ gb.add_file(pf)+ parsed.append(pf)+ gb.build()++ released: list[str] = []+ real = FileDataflowCache.release++ def _spy(self, abs_path):+ released.append(abs_path)+ real(self, abs_path)++ monkeypatch.setattr(FileDataflowCache, "release", _spy)+ analyzer = HealthAnalyzer(gb.graph(), parsed_files=parsed)+ if use_async:+ asyncio.run(analyzer.analyze_async())+ else:+ analyzer.analyze()+ assert sorted(released) == sorted(str(pf.file_info.abs_path) for pf in parsed)