mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-11-27 03:07:10 +08:00
Three sites did work per definition that grew with the file. The struct field fold scanned all of a file's definitions for every struct; it now chains each owner's fields once (lookup probes 4.00x to 2.00x when the file doubles). Every top-level C# class walked the compilation unit's children by index to find a file-scoped namespace, and each index call steps over the children before it; the namespace is now found once per file with a cursor (sibling steps 7.99x to 2.00x). The doc memo never refreshed an entry found as an ancestor, so a wide root was evicted by its children's narrow lists and listed again every few definitions; use now keeps it cached (3.99x to 2.00x). The growth tests complexity_struct_field_fold_is_linear, complexity_csharp_namespace_lookup_is_linear and complexity_doc_lookup_keeps_a_wide_root_cached count work through new seam-only counters (resolve_stats.h), never time; product builds compile the counters out. No graph content changes: flask, helm, nccl and jellyfin index identically before and after. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
48 lines
1.5 KiB
C
48 lines
1.5 KiB
C
/*
|
|
* resolve_stats.c — deterministic work counters for growth tests (see the header).
|
|
*/
|
|
#include "resolve_stats.h"
|
|
|
|
#ifdef CBM_ENABLE_TEST_SEAMS
|
|
#include <stddef.h>
|
|
|
|
static _Thread_local cbm_resolve_stats_t *current_stats;
|
|
|
|
void cbm_resolve_stats_reset(cbm_resolve_stats_t *stats) {
|
|
if (stats) {
|
|
for (unsigned i = 0; i < CBM_RESOLVE_STAT_COUNT; i++) {
|
|
atomic_init(&stats->values[i], 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
cbm_resolve_stats_t *cbm_resolve_stats_bind(cbm_resolve_stats_t *stats) {
|
|
cbm_resolve_stats_t *previous = current_stats;
|
|
current_stats = stats;
|
|
return previous;
|
|
}
|
|
|
|
void cbm_resolve_stats_add(cbm_resolve_stat_t event, uint64_t amount) {
|
|
if (current_stats && (unsigned)event < CBM_RESOLVE_STAT_COUNT) {
|
|
atomic_fetch_add_explicit(¤t_stats->values[event], amount, memory_order_relaxed);
|
|
}
|
|
}
|
|
|
|
cbm_resolve_stats_snapshot_t cbm_resolve_stats_snapshot(const cbm_resolve_stats_t *stats) {
|
|
cbm_resolve_stats_snapshot_t result = {0};
|
|
if (stats) {
|
|
for (unsigned i = 0; i < CBM_RESOLVE_STAT_COUNT; i++) {
|
|
result.values[i] = atomic_load_explicit(&stats->values[i], memory_order_relaxed);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
const char *cbm_resolve_stat_name(cbm_resolve_stat_t event) {
|
|
static const char *const names[] = {"lookup_probes", "syntax_child_steps"};
|
|
_Static_assert(sizeof(names) / sizeof(names[0]) == CBM_RESOLVE_STAT_COUNT,
|
|
"one name per counter");
|
|
return (unsigned)event < CBM_RESOLVE_STAT_COUNT ? names[event] : "unknown";
|
|
}
|
|
#endif
|