Files
codebase-memory-mcp/internal
Martin Vogel 96f6891ff2 perf(lsp): Tier 3 metadata-driven cross-LSP — skip AST re-walk for Go
KEY ARCHITECTURAL INSIGHT (credit: user observation):
The per-file LSP during extract ALREADY captures the inferred receiver
type QN + method name for unresolved cross-file calls — emit_unresolved_
call at go_lsp.c:1242-1245 stores callee_qn as '<FullReceiverTypeQN>.<
MethodName>' in result->resolved_calls flagged with strategy='lsp_
unresolved'. The cross-LSP step was REDUNDANTLY re-deriving this same
metadata via a second tree-sitter parse + AST walk.

Cross-LSP for Go is now METADATA-DRIVEN:

  cbm_go_fast_resolve_qualified_calls (rewritten):
    - Iterates result->resolved_calls where strategy=='lsp_unresolved'
    - For each entry: try direct registry lookup of callee_qn;
      if that misses, split prefix.suffix and resolve prefix via the
      file's import map then lookup '<module_qn>.<suffix>' in registry
    - Emits resolved entry on top (cbm_pipeline_find_lsp_resolution
      picks highest confidence)
    - NO tree-sitter parse, NO AST walk, NO scope tracking

  resolve_worker (pass_parallel.c):
    case CBM_LANG_GO now calls ONLY the metadata-driven fast path.
    cbm_run_go_lsp_cross_with_registry (the slow AST-walk version) is
    no longer invoked for Go — it would just re-derive identical
    metadata via a second AST walk and arrive at the same answers.

Benchmark (kubernetes, full fresh index, 12 workers):
- parallel_resolve: 1.89 min (Tier 3 meta) vs 1.86 min (Tier 2) — parity
- lsp_cross.slow lines: 0 (no tree-sitter fallback runs)
- Nodes: 297,081 vs 297,082 baseline (-1)
- Edges: 1,153,163 vs 1,153,482 baseline (-319, within 0.03%)
- Tests: 3,616 / 0 failures
- zod/serilog sanity: nodes exact, edges +1-3 (within 0.03%)

The wall-time parity is informative: the AST re-walk wasn't the
dominant cost. Per-file budget (66ms across 20,650 files / 12 workers)
is now dominated by the 5 sequential resolve passes (resolve_file_
calls/usages/throws/rw/semantic) pushing ~10M total edges into the
per-worker gbuf with arena allocs + hash-bucket inserts. The Tier 3
work eliminates a genuine architectural redundancy (two walks of the
same AST producing the same metadata) and sets up Python/C/etc to
adopt the same metadata-driven pattern in follow-up commits — but
hitting the user-target <30s K8s requires attacking the gbuf hot
path, not the cross-LSP path.
2026-05-21 13:13:16 +02:00
..