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.

Merge pull request #1679 from astandrik/codex/perf-cpp-short-name-lookups

Martin Vogel7808686ceef1
diff --cc internal/cbm/lsp/type_registry.c
index 9a3fbfaa1,ed7eddd9b..c0136b7ed
--- a/internal/cbm/lsp/type_registry.c
+++ b/internal/cbm/lsp/type_registry.c
@@@ -167,48 -167,58 +167,98 @@@ static void build_type_embed_index(CBMT
reg->type_embed_entry_count = idx;
}
+ /* Optional index: final qualified-name segment -> chain of TYPE indices.
+ * Descending iteration plus prepend preserves ascending registry scan order.
+ * Consumers opt in after the QN index captures the finalized tail boundary. */
+ void cbm_registry_build_type_short_index(CBMTypeRegistry *reg) {
+ if (!reg)
+ return;
+ reg->type_short_buckets = NULL;
+ reg->type_short_entries = NULL;
+ reg->type_short_bucket_count = 0;
+ if (!reg->arena || !reg->type_qn_buckets || reg->type_qn_bucket_count <= 0)
+ return;
+ CBMArena *idx_arena = reg->arena;
+ int count = 0;
+ for (int i = 0; i < reg->type_count; i++) {
+ if (reg->types[i].qualified_name)
+ count++;
+ }
+ if (count == 0)
+ return;
+ int bucket_count = next_pow2(count * 2);
+ if (bucket_count < 16)
+ bucket_count = 16;
+ int *buckets = (int *)cbm_arena_alloc(idx_arena, (size_t)bucket_count * sizeof(int));
+ CBMRegistryHashEntry *entries = (CBMRegistryHashEntry *)cbm_arena_alloc(
+ idx_arena, (size_t)count * sizeof(CBMRegistryHashEntry));
+ if (!buckets || !entries)
+ return;
+ for (int i = 0; i < bucket_count; i++)
+ buckets[i] = -1;
+ int idx = 0;
+ for (int i = reg->type_count - 1; i >= 0; i--) {
+ const char *qn = reg->types[i].qualified_name;
+ if (!qn)
+ continue;
+ const char *dot = strrchr(qn, '.');
+ const char *short_name = dot ? dot + 1 : qn;
+ uint64_t h = fnv1a(short_name);
+ int slot = (int)(h & (uint64_t)(bucket_count - 1));
+ entries[idx].hash = h;
+ entries[idx].payload_index = i;
+ entries[idx].next_index = buckets[slot];
+ entries[idx].slot = slot;
+ buckets[slot] = idx;
+ idx++;
+ }
+ reg->type_short_buckets = buckets;
+ reg->type_short_entries = entries;
+ reg->type_short_bucket_count = bucket_count;
+ }
+
/* Index: short_name -> chain of FREE-function (receiver_type==NULL) indices.
* Descending-iterate + prepend for ascending chain order (as above). */
+static void build_type_short_index(CBMTypeRegistry *reg, CBMArena *idx_arena) {
+ int tcount = 0;
+ for (int i = 0; i < reg->type_count; i++) {
+ if (reg->types[i].short_name)
+ tcount++;
+ }
+ if (tcount == 0)
+ return;
+ int bucket_count = next_pow2(tcount * 2);
+ if (bucket_count < 16)
+ bucket_count = 16;
+ int *buckets = (int *)cbm_arena_alloc(idx_arena, (size_t)bucket_count * sizeof(int));
+ CBMRegistryHashEntry *entries = (CBMRegistryHashEntry *)cbm_arena_alloc(
+ idx_arena, (size_t)tcount * sizeof(CBMRegistryHashEntry));
+ if (!buckets || !entries)
+ return;
+ for (int i = 0; i < bucket_count; i++)
+ buckets[i] = -1;
+ int idx = 0;
+ /* Reverse insertion so each chain yields ASCENDING types[] order — callers
+ * that used first-match-in-registration-order keep their tie-breaks. */
+ for (int i = reg->type_count - 1; i >= 0; i--) {
+ const CBMRegisteredType *t = &reg->types[i];
+ if (!t->short_name)
+ continue;
+ uint64_t h = fnv1a(t->short_name);
+ int slot = (int)(h & (uint64_t)(bucket_count - 1));
+ entries[idx].hash = h;
+ entries[idx].payload_index = i;
+ entries[idx].next_index = buckets[slot];
+ entries[idx].slot = slot;
+ buckets[slot] = idx;
+ idx++;
+ }
+ reg->type_short_buckets = buckets;
+ reg->type_short_entries = entries;
+ reg->type_short_bucket_count = bucket_count;
+ reg->type_short_entry_count = idx;
+}
+
static void build_ffunc_short_index(CBMTypeRegistry *reg, CBMArena *idx_arena) {
int fcount = 0;
for (int i = 0; i < reg->func_count; i++) {