Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

perf(git): share one blame entry per commit instead of one per line (#2867)

Raghav Chamadiyafea65c8fcda5
diff --git a/packages/core/src/repowise/core/ingestion/git_indexer/function_blame.py b/packages/core/src/repowise/core/ingestion/git_indexer/function_blame.py
index 27d78a2a5..cc6924920 100644
--- a/packages/core/src/repowise/core/ingestion/git_indexer/function_blame.py
+++ b/packages/core/src/repowise/core/ingestion/git_indexer/function_blame.py
@@ -155,6 +155,10 @@ def _parse_porcelain(
# Cache author-time per sha — porcelain only emits headers the first
# time a sha appears; subsequent blocks repeat sha + line numbers only.
sha_author_time: dict[str, int] = {}
+ # One shared ``(sha, time)`` tuple per commit instead of a fresh tuple,
+ # sha string and int per line: the index stays alive from the git stage
+ # until health finishes, and per-line copies tripled its size.
+ entries: dict[tuple[str, int], tuple[str, int]] = {}
for line in raw.splitlines():
if not line:
@@ -162,7 +166,8 @@ def _parse_porcelain(
if line.startswith("\t"):
if current_sha is not None and current_final is not None:
t = current_author_time or sha_author_time.get(current_sha, 0)
- out[current_final] = (current_sha, t)
+ entry = (current_sha, t)
+ out[current_final] = entries.setdefault(entry, entry)
if current_sha not in authors and current_author_name:
authors[current_sha] = (
current_author_name,
diff --git a/tests/unit/health/test_function_blame.py b/tests/unit/health/test_function_blame.py
index b2cbf9e44..6854dd78c 100644
--- a/tests/unit/health/test_function_blame.py
+++ b/tests/unit/health/test_function_blame.py
@@ -52,6 +52,14 @@ def test_parse_porcelain_indexes_each_final_line():
assert lines[4] == ("cccccccccccccccccccccccccccccccccccccccc", 1755000000)
+def test_parse_porcelain_shares_one_entry_per_commit():
+ # Lines from the same commit hold the same tuple, so the index costs one
+ # entry per commit rather than one tuple and sha string per line.
+ lines, _ = _parse_porcelain(_PORCELAIN)
+ assert lines[1] is lines[2]
+ assert lines[1] is not lines[3]
+
+
def test_distinct_commits_in_range():
idx = BlameIndex(lines=_parse_porcelain(_PORCELAIN)[0])
# Range 1-2 → single sha (a*).