Skip to content

Commit 8c85941

Browse files
committed
perf(diffctx): eliminate duplicate get_ignore_specs call (33% speedup)
Pass combined_spec through DiscoveryContext instead of recomputing in DefaultDiscovery. Profiling showed get_ignore_specs was called twice, consuming 6.8s of 10.9s total (63%). Now called once. Measured: 10.87s → 7.26s on treemapper repo.
1 parent dc16701 commit 8c85941

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

src/treemapper/diffctx/pipeline.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ def build_diff_context(
244244
diff_text=diff_text,
245245
expansion_concepts=frozenset(expansion_concepts),
246246
file_cache=file_cache,
247+
combined_spec=combined_spec,
247248
)
248249
discovered_files = _create_discovery(config).discover(discovery_ctx)
249250
discovered_files = [_normalize_path(p, root_dir) for p in discovered_files]

src/treemapper/diffctx/scoring.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from abc import ABC, abstractmethod
44
from dataclasses import dataclass
55
from pathlib import Path
6+
from typing import Any
67

78
from .graph import Graph
89
from .types import DiffHunk, Fragment, FragmentId
@@ -16,6 +17,7 @@ class DiscoveryContext:
1617
diff_text: str
1718
expansion_concepts: frozenset[str]
1819
file_cache: dict[Path, str] | None = None
20+
combined_spec: Any | None = None
1921

2022
def read_file(self, path: Path) -> str | None:
2123
if self.file_cache is not None and path in self.file_cache:
@@ -42,7 +44,7 @@ def discover(self, ctx: DiscoveryContext) -> list[Path]:
4244

4345
from ..ignore import get_ignore_specs
4446

45-
combined_spec = get_ignore_specs(ctx.root_dir, None, False, None)
47+
combined_spec = ctx.combined_spec or get_ignore_specs(ctx.root_dir, None, False, None)
4648
expanded = _expand_universe_by_rare_identifiers(
4749
ctx.root_dir,
4850
ctx.expansion_concepts,

0 commit comments

Comments
 (0)