Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

perf(lsp): Tier 2 — pre-built per-language cross-LSP registries (Go + Python)

Martin Vogel23d404a05606
diff --git a/internal/cbm/lsp/go_lsp.c b/internal/cbm/lsp/go_lsp.c
index 40e2fae9e..8341ae99f 100644
--- a/internal/cbm/lsp/go_lsp.c
+++ b/internal/cbm/lsp/go_lsp.c
@@ -2709,6 +2709,124 @@ void cbm_run_go_lsp_cross(
}
}
+/* ── Tier 2: pre-built per-language registry (gopls package summary pattern) ──
+ *
+ * cbm_go_build_cross_registry runs the registry build ONCE per project (in
+ * pipeline.c, before the parallel resolve workers fire). The returned
+ * registry is finalized (O(1) lookups) and shared READ-ONLY across all
+ * workers in the resolve phase.
+ *
+ * cbm_run_go_lsp_cross_with_registry is the per-file entrypoint used by
+ * the resolve worker. It SKIPS the registry build (uses the pre-built reg)
+ * AND skips Phase 1b/1c AST scans (those mutate the registry, which would
+ * race with other workers reading the shared reg). Accuracy trade-off:
+ * file-local type aliases and struct embeddings discovered ONLY by Phase
+ * 1b (and not already in defs[] embedded_types/field_defs strings) are
+ * missed. In practice the per-file LSP during extract already captures
+ * those via the def strings. */
+CBMTypeRegistry* cbm_go_build_cross_registry(
+ CBMArena* arena, CBMLSPDef* defs, int def_count) {
+ if (!arena) return NULL;
+ CBMTypeRegistry* reg = (CBMTypeRegistry*)cbm_arena_alloc(arena, sizeof(*reg));
+ if (!reg) return NULL;
+ cbm_registry_init(reg, arena);
+ cbm_go_stdlib_register(reg, arena);
+
+ for (int i = 0; i < def_count; i++) {
+ CBMLSPDef* d = &defs[i];
+ if (!d->qualified_name || !d->short_name || !d->label) continue;
+ /* Filter to Go defs only — the all_defs[] array is mixed-language. */
+ if (d->lang != CBM_LANG_GO) continue;
+ /* In the pre-built path every def carries its own def_module_qn
+ * (set by cbm_pxc_collect_all_defs). There is no caller module to
+ * fall back to — this registry is project-wide, not per-file. */
+ const char* def_mod = d->def_module_qn ? d->def_module_qn : "";
+
+ if (strcmp(d->label, "Type") == 0 || strcmp(d->label, "Class") == 0 ||
+ strcmp(d->label, "Interface") == 0) {
+ CBMRegisteredType rt;
+ memset(&rt, 0, sizeof(rt));
+ rt.qualified_name = d->qualified_name; /* borrowed */
+ rt.short_name = d->short_name;
+ rt.is_interface = d->is_interface || strcmp(d->label, "Interface") == 0;
+ rt.embedded_types = split_pipe_strings(arena, d->embedded_types);
+ if (rt.is_interface && d->method_names_str && d->method_names_str[0]) {
+ rt.method_names = split_pipe_strings(arena, d->method_names_str);
+ }
+ cbm_registry_add_type(reg, rt);
+ if (d->field_defs && d->field_defs[0]) {
+ parse_field_defs_into_type(arena, reg, rt.qualified_name,
+ d->field_defs, def_mod);
+ }
+ }
+
+ if (strcmp(d->label, "Function") == 0 || strcmp(d->label, "Method") == 0) {
+ CBMRegisteredFunc rf;
+ memset(&rf, 0, sizeof(rf));
+ rf.qualified_name = d->qualified_name; /* borrowed */
+ rf.short_name = d->short_name;
+ const CBMType** ret_types = split_pipe_types(arena, d->return_types, def_mod);
+ rf.signature = cbm_type_func(arena, NULL, NULL, ret_types);
+ if (strcmp(d->label, "Method") == 0 && d->receiver_type && d->receiver_type[0]) {
+ rf.receiver_type = d->receiver_type;
+ if (!cbm_registry_lookup_type(reg, rf.receiver_type)) {
+ CBMRegisteredType auto_type;
+ memset(&auto_type, 0, sizeof(auto_type));
+ auto_type.qualified_name = rf.receiver_type;
+ const char* dot = strrchr(d->receiver_type, '.');
+ auto_type.short_name = dot ? dot + 1 : rf.receiver_type;
+ cbm_registry_add_type(reg, auto_type);
+ }
+ }
+ cbm_registry_add_func(reg, rf);
+ }
+ }
+
+ cbm_registry_finalize(reg);
+ return reg;
+}
+
+void cbm_run_go_lsp_cross_with_registry(
+ CBMArena* arena,
+ const char* source, int source_len,
+ const char* module_qn,
+ CBMTypeRegistry* reg,
+ const char** import_names, const char** import_qns, int import_count,
+ TSTree* cached_tree,
+ CBMResolvedCallArray* out) {
+ if (!source || source_len <= 0 || !reg) return;
+
+ TSParser* parser = NULL;
+ TSTree* tree = cached_tree;
+ bool owns_tree = false;
+ if (!tree) {
+ parser = ts_parser_new();
+ if (!parser) return;
+ ts_parser_set_language(parser, tree_sitter_go());
+ tree = ts_parser_parse_string(parser, NULL, source, source_len);
+ owns_tree = true;
+ if (!tree) { ts_parser_delete(parser); return; }
+ }
+ TSNode root = ts_tree_root_node(tree);
+
+ /* Phase 1b/1c (per-file AST mutations on registry) DELIBERATELY SKIPPED —
+ * shared registry must stay immutable across parallel workers. */
+
+ GoLSPContext ctx;
+ go_lsp_init(&ctx, arena, source, source_len, reg, module_qn, out);
+ for (int i = 0; i < import_count; i++) {
+ if (import_names[i] && import_qns[i]) {
+ go_lsp_add_import(&ctx, import_names[i], import_qns[i]);
+ }
+ }
+ go_lsp_process_file(&ctx, root);
+
+ if (owns_tree) {
+ ts_tree_delete(tree);
+ if (parser) ts_parser_delete(parser);
+ }
+}
+
// --- Batch cross-file LSP ---
void cbm_batch_go_lsp_cross(
diff --git a/internal/cbm/lsp/go_lsp.h b/internal/cbm/lsp/go_lsp.h
index 277d93962..e274cefde 100644
--- a/internal/cbm/lsp/go_lsp.h
+++ b/internal/cbm/lsp/go_lsp.h
@@ -81,6 +81,7 @@ typedef struct {
const char* field_defs; // "|"-separated "name:type" pairs (for struct fields, e.g. "Binder:Binder|Name:string")
const char* method_names_str; // "|"-separated method names for interfaces (e.g. "Get|Put|Delete")
bool is_interface;
+ CBMLanguage lang; // language of the file that defined this — used by Tier 2 per-language registry build to filter all_defs
} CBMLSPDef;
// Parse source, build registry from defs + stdlib, run LSP.
@@ -97,6 +98,24 @@ void cbm_run_go_lsp_cross(
TSTree* cached_tree, // NULL = parse internally
CBMResolvedCallArray* out);
+/* Tier 2 (gopls package-summary pattern):
+ * Build a project-wide, finalized CBMTypeRegistry from all Go defs ONCE.
+ * Run cross-file LSP per file using that shared registry — no per-file
+ * registry build, O(1) lookups, no Phase 1b/1c mutations. Reg is borrowed
+ * from arena (arena owns the storage); reg pointer is valid for arena
+ * lifetime. */
+CBMTypeRegistry* cbm_go_build_cross_registry(
+ CBMArena* arena, CBMLSPDef* defs, int def_count);
+
+void cbm_run_go_lsp_cross_with_registry(
+ CBMArena* arena,
+ const char* source, int source_len,
+ const char* module_qn,
+ CBMTypeRegistry* reg, // pre-built, finalized, READ-ONLY
+ const char** import_names, const char** import_qns, int import_count,
+ TSTree* cached_tree, // NULL = parse internally
+ CBMResolvedCallArray* out);
+
// --- Batch cross-file LSP ---
// Per-file input for batch Go LSP processing.
diff --git a/internal/cbm/lsp/py_lsp.c b/internal/cbm/lsp/py_lsp.c
index 25cc5e634..a13bbf497 100644
--- a/internal/cbm/lsp/py_lsp.c
+++ b/internal/cbm/lsp/py_lsp.c
@@ -3111,6 +3111,7 @@ void cbm_run_py_lsp_cross(
CBMTypeRegistry reg;
cbm_registry_init(&reg, arena);
cbm_python_stdlib_register(&reg, arena);
+ /* per-file path: defs[] already filtered by caller, no lang-check needed */
py_register_lsp_defs(arena, &reg, defs, def_count);
/* Finalize registry — O(1) lookups. See go_lsp.c "3c. Finalize"
@@ -3130,6 +3131,63 @@ void cbm_run_py_lsp_cross(
if (parser) ts_parser_delete(parser);
}
+/* ── Tier 2: pre-built per-language registry (mirrors Go pilot) ── */
+CBMTypeRegistry* cbm_py_build_cross_registry(
+ CBMArena* arena, CBMLSPDef* defs, int def_count) {
+ if (!arena) return NULL;
+ CBMTypeRegistry* reg = (CBMTypeRegistry*)cbm_arena_alloc(arena, sizeof(*reg));
+ if (!reg) return NULL;
+ cbm_registry_init(reg, arena);
+ cbm_python_stdlib_register(reg, arena);
+
+ /* Filter to Python defs only — defs[] is mixed-language all_defs. */
+ for (int i = 0; i < def_count; i++) {
+ CBMLSPDef* d = &defs[i];
+ if (d->lang != CBM_LANG_PYTHON) continue;
+ /* Reuse the existing register fn on a single-def slice (n=1 inline). */
+ py_register_lsp_defs(arena, reg, d, 1);
+ }
+
+ cbm_registry_finalize(reg);
+ return reg;
+}
+
+void cbm_run_py_lsp_cross_with_registry(
+ CBMArena* arena,
+ const char* source, int source_len,
+ const char* module_qn,
+ CBMTypeRegistry* reg,
+ const char** import_names, const char** import_qns, int import_count,
+ TSTree* cached_tree,
+ CBMResolvedCallArray* out) {
+ if (!arena || !source || source_len <= 0 || !out || !reg) return;
+
+ TSParser* parser = NULL;
+ TSTree* tree = cached_tree;
+ bool owns_tree = false;
+ if (!tree) {
+ parser = ts_parser_new();
+ if (!parser) return;
+ ts_parser_set_language(parser, tree_sitter_python());
+ tree = ts_parser_parse_string(parser, NULL, source, (uint32_t)source_len);
+ owns_tree = true;
+ if (!tree) { ts_parser_delete(parser); return; }
+ }
+ TSNode root = ts_tree_root_node(tree);
+
+ PyLSPContext ctx;
+ py_lsp_init(&ctx, arena, source, source_len, reg, module_qn, out);
+ for (int i = 0; i < import_count; i++) {
+ if (import_names && import_qns && import_names[i] && import_qns[i]) {
+ py_lsp_add_import(&ctx, import_names[i], import_qns[i]);
+ }
+ }
+ py_lsp_process_file(&ctx, root);
+
+ if (owns_tree && tree) ts_tree_delete(tree);
+ if (parser) ts_parser_delete(parser);
+}
+
void cbm_batch_py_lsp_cross(
CBMArena* arena,
CBMBatchPyLSPFile* files, int file_count,
diff --git a/internal/cbm/lsp/py_lsp.h b/internal/cbm/lsp/py_lsp.h
index 841bafec6..670717755 100644
--- a/internal/cbm/lsp/py_lsp.h
+++ b/internal/cbm/lsp/py_lsp.h
@@ -102,6 +102,20 @@ void cbm_run_py_lsp_cross(
TSTree* cached_tree, // NULL = parse internally
CBMResolvedCallArray* out);
+/* Tier 2: pre-built per-language registry (mirrors Go pilot).
+ * Filters all_defs to Python entries, builds + finalizes once. */
+CBMTypeRegistry* cbm_py_build_cross_registry(
+ CBMArena* arena, CBMLSPDef* defs, int def_count);
+
+void cbm_run_py_lsp_cross_with_registry(
+ CBMArena* arena,
+ const char* source, int source_len,
+ const char* module_qn,
+ CBMTypeRegistry* reg, // pre-built, finalized, READ-ONLY
+ const char** import_names, const char** import_qns, int import_count,
+ TSTree* cached_tree,
+ CBMResolvedCallArray* out);
+
// --- Batch cross-file LSP ---
typedef struct {
diff --git a/src/pipeline/pass_lsp_cross.c b/src/pipeline/pass_lsp_cross.c
index cc7d26ef4..e340dd911 100644
--- a/src/pipeline/pass_lsp_cross.c
+++ b/src/pipeline/pass_lsp_cross.c
@@ -125,7 +125,8 @@ static const char *pxc_join_pipe(CBMArena *arena, const char *const *items) {
* to skip (unsupported label or missing required field). dst gets borrowed
* pointers into src and into `arena` for synthesised composites. */
static int pxc_build_lsp_def(CBMArena *arena, const CBMDefinition *src,
- const char *module_qn, CBMLSPDef *dst) {
+ const char *module_qn, CBMLanguage lang,
+ CBMLSPDef *dst) {
const char *label = pxc_map_label(src->label);
if (!label || !src->qualified_name || !src->name) return -1;
memset(dst, 0, sizeof(*dst));
@@ -141,6 +142,7 @@ static int pxc_build_lsp_def(CBMArena *arena, const CBMDefinition *src,
* piece, which is what's already stored. */
dst->return_types = src->return_type;
dst->embedded_types = pxc_join_pipe(arena, src->base_classes);
+ dst->lang = lang;
return 0;
}
@@ -174,6 +176,7 @@ CBMLSPDef *cbm_pxc_collect_all_defs(CBMFileResult **cache,
if (pxc_build_lsp_def(&cache[fi]->arena,
&cache[fi]->defs.items[di],
def_modules[fi],
+ files[fi].language,
&defs[idx]) == 0) {
idx++;
}
diff --git a/src/pipeline/pass_lsp_cross.h b/src/pipeline/pass_lsp_cross.h
index e1703d734..578ddaf8b 100644
--- a/src/pipeline/pass_lsp_cross.h
+++ b/src/pipeline/pass_lsp_cross.h
@@ -93,6 +93,43 @@ CBMLSPDef *cbm_pxc_filter_defs_for_file(const CBMModuleDefIndex *idx,
int imp_count,
int *out_count);
+/* ── Tier 2 full: pre-built per-language cross-LSP registries ─────
+ *
+ * Each non-NULL registry is built ONCE in pipeline.c (in a dedicated
+ * cross_lsp_arena), finalized, and shared READ-ONLY across all
+ * resolve workers for files of that language. The worker uses the
+ * matching cbm_run_X_lsp_cross_with_registry variant which skips the
+ * per-file registry build entirely. NULL → fall back to the per-file
+ * cbm_pxc_run_one path. */
+typedef struct {
+ CBMTypeRegistry *go; /* CBM_LANG_GO */
+ CBMTypeRegistry *c; /* CBM_LANG_C, CBM_LANG_CPP, CBM_LANG_CUDA */
+ CBMTypeRegistry *python; /* CBM_LANG_PYTHON */
+ CBMTypeRegistry *ts; /* CBM_LANG_JAVASCRIPT, TYPESCRIPT, TSX */
+ CBMTypeRegistry *php; /* CBM_LANG_PHP */
+ CBMTypeRegistry *cs; /* CBM_LANG_CSHARP */
+} CBMCrossLspRegistries;
+
+/* Return the appropriate pre-built registry for a language, or NULL
+ * if none was built (or language has no cross-LSP entrypoint). */
+static inline CBMTypeRegistry *cbm_pxc_registry_for_lang(
+ const CBMCrossLspRegistries *r, CBMLanguage lang) {
+ if (!r) return NULL;
+ switch (lang) {
+ case CBM_LANG_GO: return r->go;
+ case CBM_LANG_C: /* fallthrough */
+ case CBM_LANG_CPP: /* fallthrough */
+ case CBM_LANG_CUDA: return r->c;
+ case CBM_LANG_PYTHON: return r->python;
+ case CBM_LANG_JAVASCRIPT: /* fallthrough */
+ case CBM_LANG_TYPESCRIPT: /* fallthrough */
+ case CBM_LANG_TSX: return r->ts;
+ case CBM_LANG_PHP: return r->php;
+ case CBM_LANG_CSHARP: return r->cs;
+ default: return NULL;
+ }
+}
+
/* Run the cross-file LSP resolver for non-TS languages. Appends
* resolved CALLS into r->resolved_calls (lives in r->arena). Caller
* owns source, module_qn, all_defs, imp_keys, imp_vals.
diff --git a/src/pipeline/pass_parallel.c b/src/pipeline/pass_parallel.c
index 2c23c995f..ae22595ad 100644
--- a/src/pipeline/pass_parallel.c
+++ b/src/pipeline/pass_parallel.c
@@ -896,6 +896,10 @@ typedef struct {
* to shrink the def array passed to the LSP from O(all_defs) to
* O(relevant_defs). NULL → each file sees the full all_defs[]. */
struct CBMModuleDefIndex *module_def_index;
+ /* Tier 2 full: pre-built per-language registries (project-wide,
+ * finalized, READ-ONLY). When non-NULL for a lang, the worker uses
+ * cbm_run_X_lsp_cross_with_registry — skip per-file build entirely. */
+ struct CBMCrossLspRegistries *cross_registries;
/* Counters for parallel.resolve.lsp_cross_done summary. */
_Atomic int lsp_cross_processed;
@@ -1822,39 +1826,69 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {
? rc->def_modules[file_idx]
: module_qn;
- /* gopls pattern: filter all_defs down to just the defs
- * this file actually needs (own_module + imp_vals
- * imported modules). For a typical file with ~10
- * imports, this slashes the per-file registry-build
- * cost from O(all_defs) to O(relevant_defs) — usually
- * 50-100× smaller. */
- CBMLSPDef *file_defs = rc->all_defs;
- int file_def_count = rc->def_count;
- CBMLSPDef *filtered = NULL;
- if (rc->module_def_index) {
- int filtered_count = 0;
- filtered = cbm_pxc_filter_defs_for_file(
- rc->module_def_index, rc->all_defs,
- def_module, imp_vals, imp_count,
- &filtered_count);
- if (filtered) {
- file_defs = filtered;
- file_def_count = filtered_count;
+ uint64_t lsp_t0 = extract_now_ns();
+
+ /* Tier 2 full fast path: pre-built per-language registry.
+ * When available, skip the per-file registry build entirely
+ * and pass the shared finalized registry. Dispatch per-lang
+ * to the appropriate _with_registry variant. */
+ bool used_prebuilt = false;
+ CBMTypeRegistry *prebuilt =
+ cbm_pxc_registry_for_lang(rc->cross_registries, lang);
+ if (prebuilt) {
+ switch (lang) {
+ case CBM_LANG_GO:
+ cbm_run_go_lsp_cross_with_registry(
+ &result->arena, result->source, result->source_len,
+ def_module, prebuilt,
+ imp_keys, imp_vals, imp_count,
+ result->cached_tree, &result->resolved_calls);
+ used_prebuilt = true;
+ break;
+ case CBM_LANG_PYTHON:
+ cbm_run_py_lsp_cross_with_registry(
+ &result->arena, result->source, result->source_len,
+ def_module, prebuilt,
+ imp_keys, imp_vals, imp_count,
+ result->cached_tree, &result->resolved_calls);
+ used_prebuilt = true;
+ break;
+ /* C/C++/CUDA, TS/JS/TSX, PHP, C# fall through to the
+ * per-file build path below until their _with_registry
+ * variants are added in follow-up commits. */
+ default:
+ break;
}
}
- uint64_t lsp_t0 = extract_now_ns();
- if (lang == CBM_LANG_JAVASCRIPT || lang == CBM_LANG_TYPESCRIPT ||
- lang == CBM_LANG_TSX) {
- bool js, jsx, dts;
- cbm_pxc_ts_modes(lang, rel, &js, &jsx, &dts);
- cbm_pxc_run_one_ts(result, result->source, result->source_len,
- def_module, file_defs, file_def_count,
- imp_keys, imp_vals, imp_count, js, jsx, dts);
- } else {
- cbm_pxc_run_one(lang, result, result->source, result->source_len,
- def_module, file_defs, file_def_count,
- imp_keys, imp_vals, imp_count);
+ CBMLSPDef *filtered = NULL;
+ if (!used_prebuilt) {
+ /* Fallback: gopls per-file filter + per-file registry build. */
+ CBMLSPDef *file_defs = rc->all_defs;
+ int file_def_count = rc->def_count;
+ if (rc->module_def_index) {
+ int filtered_count = 0;
+ filtered = cbm_pxc_filter_defs_for_file(
+ rc->module_def_index, rc->all_defs,
+ def_module, imp_vals, imp_count,
+ &filtered_count);
+ if (filtered) {
+ file_defs = filtered;
+ file_def_count = filtered_count;
+ }
+ }
+ if (lang == CBM_LANG_JAVASCRIPT || lang == CBM_LANG_TYPESCRIPT ||
+ lang == CBM_LANG_TSX) {
+ bool js, jsx, dts;
+ cbm_pxc_ts_modes(lang, rel, &js, &jsx, &dts);
+ cbm_pxc_run_one_ts(result, result->source, result->source_len,
+ def_module, file_defs, file_def_count,
+ imp_keys, imp_vals, imp_count, js, jsx, dts);
+ } else {
+ cbm_pxc_run_one(lang, result, result->source, result->source_len,
+ def_module, file_defs, file_def_count,
+ imp_keys, imp_vals, imp_count);
+ }
}
free(filtered);
cbm_slab_reclaim();
@@ -1896,7 +1930,8 @@ int cbm_parallel_resolve(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
CBMFileResult **result_cache, _Atomic int64_t *shared_ids,
int worker_count, CBMLSPDef *all_defs, int def_count,
char *const *def_modules,
- struct CBMModuleDefIndex *module_def_index) {
+ struct CBMModuleDefIndex *module_def_index,
+ struct CBMCrossLspRegistries *cross_registries) {
if (file_count == 0) {
return 0;
}
@@ -1927,6 +1962,7 @@ int cbm_parallel_resolve(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
.def_count = def_count,
.def_modules = def_modules,
.module_def_index = module_def_index,
+ .cross_registries = cross_registries,
};
atomic_init(&rc.next_file_idx, 0);
atomic_init(&rc.lsp_cross_processed, 0);
diff --git a/src/pipeline/pipeline.c b/src/pipeline/pipeline.c
index 9271cb70d..1eabe7e42 100644
--- a/src/pipeline/pipeline.c
+++ b/src/pipeline/pipeline.c
@@ -597,15 +597,30 @@ static int run_parallel_pipeline(cbm_pipeline_t *p, cbm_pipeline_ctx_t *ctx,
* smaller per file. */
CBMModuleDefIndex *module_def_index =
all_defs ? cbm_pxc_build_module_def_index(all_defs, def_count) : NULL;
+ /* Tier 2 full: pre-build per-language cross-LSP registries.
+ * Built ONCE here; shared READ-ONLY across all files of that language
+ * during resolve. Per-file work is then: parse + AST walk + O(1) lookups
+ * — no registry build, no Phase 1b mutations. Languages added so far:
+ * Go, Python. Others (C/C++, TS/JS, PHP, C#) fall back to per-file. */
+ CBMArena cross_lsp_arena;
+ cbm_arena_init(&cross_lsp_arena);
+ CBMCrossLspRegistries cross_registries = {0};
+ if (all_defs) {
+ cross_registries.go =
+ cbm_go_build_cross_registry(&cross_lsp_arena, all_defs, def_count);
+ cross_registries.python =
+ cbm_py_build_cross_registry(&cross_lsp_arena, all_defs, def_count);
+ }
cbm_log_info("pass.timing", "pass", "lsp_cross_prepare", "elapsed_ms",
itoa_buf((int)elapsed_ms(*t)));
cbm_clock_gettime(CLOCK_MONOTONIC, t);
rc = cbm_parallel_resolve(ctx, files, file_count, cache, &shared_ids,
worker_count, all_defs, def_count, def_modules,
- module_def_index);
+ module_def_index, &cross_registries);
cbm_log_info("pass.timing", "pass", "parallel_resolve", "elapsed_ms",
itoa_buf((int)elapsed_ms(*t)));
cbm_pxc_free_module_def_index(module_def_index);
+ cbm_arena_destroy(&cross_lsp_arena); /* releases all per-lang registries */
free(all_defs);
if (def_modules) {
for (int i = 0; i < file_count; i++) {
diff --git a/src/pipeline/pipeline_incremental.c b/src/pipeline/pipeline_incremental.c
index 1f52c3124..a0edee8d1 100644
--- a/src/pipeline/pipeline_incremental.c
+++ b/src/pipeline/pipeline_incremental.c
@@ -411,7 +411,9 @@ static void run_extract_resolve(cbm_pipeline_ctx_t *ctx, cbm_file_info_t *change
* step in resolve_worker a no-op. */
cbm_clock_gettime(CLOCK_MONOTONIC, &t);
cbm_parallel_resolve(ctx, changed_files, ci, cache, &shared_ids,
- worker_count, NULL, 0, NULL, NULL);
+ worker_count, NULL, 0, NULL,
+ NULL /* module_def_index */,
+ NULL /* cross_registries — incremental skips Tier 2 prebuild */);
cbm_gbuf_set_next_id(ctx->gbuf, atomic_load(&shared_ids));
cbm_log_info("pass.timing", "pass", "incr_resolve", "elapsed_ms",
itoa_buf((int)elapsed_ms(t)));
diff --git a/src/pipeline/pipeline_internal.h b/src/pipeline/pipeline_internal.h
index f0a158e9a..91c4e0007 100644
--- a/src/pipeline/pipeline_internal.h
+++ b/src/pipeline/pipeline_internal.h
@@ -369,6 +369,9 @@ int cbm_build_registry_from_cache(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t
* pulling the pass header into every consumer of pipeline_internal.h. */
struct CBMModuleDefIndex;
+/* Forward-declared in pass_lsp_cross.h. */
+struct CBMCrossLspRegistries;
+
int cbm_parallel_resolve(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files, int file_count,
CBMFileResult **result_cache, _Atomic int64_t *shared_ids,
int worker_count,
@@ -378,11 +381,15 @@ int cbm_parallel_resolve(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
* worker forwards them to). Pass NULL/0/NULL to skip. */
CBMLSPDef *all_defs, int def_count,
char *const *def_modules,
- /* Optional inverted index module_qn → defs[] — when
- * present, the fused worker filters the global all_defs
- * down to just the per-file relevant subset (gopls pattern).
- * Pass NULL to disable filtering (each file sees all_defs). */
- struct CBMModuleDefIndex *module_def_index);
+ /* Optional inverted index module_qn → defs[] — fallback
+ * path when there's no pre-built registry for this lang. */
+ struct CBMModuleDefIndex *module_def_index,
+ /* Optional Tier 2 full: pre-built per-language registries.
+ * For each language with a non-NULL entry, workers use the
+ * cbm_run_X_lsp_cross_with_registry fast path (skip per-
+ * file registry build entirely). Falls back to the filter
+ * + per-file build path when entry is NULL or struct is NULL. */
+ struct CBMCrossLspRegistries *cross_registries);
/* Post-merge: create Route nodes for HTTP_CALLS/ASYNC_CALLS edges that
* have url_path in properties but point to library functions instead of routes.
diff --git a/tests/test_parallel.c b/tests/test_parallel.c
index 734638bf2..147adca3a 100644
--- a/tests/test_parallel.c
+++ b/tests/test_parallel.c
@@ -153,7 +153,8 @@ static cbm_gbuf_t *run_parallel(const char *project, const char *repo_path, cbm_
cbm_parallel_resolve(&ctx, files, file_count, result_cache, &shared_ids,
worker_count, all_defs, def_count, def_modules,
- module_def_index);
+ module_def_index,
+ NULL /* cross_registries — tests use per-file path */);
cbm_gbuf_set_next_id(gbuf, atomic_load(&shared_ids));
cbm_pxc_free_module_def_index(module_def_index);