activeloopai / activeloopai/hivemind

Perf: suffix-keyed reverse index for matchPythonSuffix (avoid O(files) scan per import)

Offen
#236 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
TypeScript
Sterne
1.6k
Forks
107
Ø Merge
17 Std. 30 Min.
Gemergte PRs (30 T.)
6

Beschreibung

## Context

`matchPythonSuffix` in `src/graph/resolve/cross-file.ts` resolves a dotted-absolute Python import by suffix-matching against the known-files set. For each lookup it does up to 4 target forms × a full linear scan of `knownFiles`:

```ts
for (const t of targets) { // 4 target forms
if (knownFiles.has(t)) return t;
for (const f of knownFiles) { // O(files) scan
if (f.endsWith(`/${t}`)) { ... }
}
}
```

So cross-file resolution over a Python repo is `O(calls × files × 4)`. Fine at current scale (graphiti = 117 files, instant), but it degrades on large monorepos.

## Proposal

Build a suffix-keyed reverse index **once** (alongside `buildExportIndex`), mapping every path suffix (`mod.py`, `sub/mod.py`, `pkg/sub/mod.py`) → list of files, then make `matchPythonSuffix` an O(1) lookup + ambiguity check with no per-call scan.

## Notes
- Raised by CodeRabbit on PR #228 (Perf, Medium). Deferred from that PR since it's an optimization, not a correctness fix.
- Keep the existing high-confidence semantics: exact (root-anchored) wins; single suffix match wins; multiple → drop (ambiguous).

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.