Skip to content

Commit 926e818

Browse files
committed
feat(ui): honor the requested node budget up to a 10M ceiling
The layout endpoint treated the default render cap (2000) as a ceiling: an explicit max_nodes above it was silently clamped back down, so the UI could never show more than 2000 nodes regardless of the request. Make the default a default — an explicit request is now honored up to a hard ceiling of 10M nodes; CBM_UI_MAX_RENDER_NODES still adjusts the ceiling for constrained deployments. The default budget rises to 5000, and the layout refinement pass scales its iteration count down past 100k/500k bodies to keep very large budgets responsive. Edges need no changes: the layout already returns every edge between loaded nodes. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 5554f8a commit 926e818

3 files changed

Lines changed: 69 additions & 7 deletions

File tree

‎src/ui/http_server.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ static void handle_layout(cbm_http_conn_t *c, const cbm_http_req_t *req) {
13331333
return;
13341334
}
13351335

1336-
int max_nodes = 50000;
1336+
int max_nodes = 0; /* 0 → layout default budget */
13371337
if (cbm_http_query_param(req->query, "max_nodes", max_str, (int)sizeof(max_str))) {
13381338
int v = atoi(max_str);
13391339
if (v > 0)

‎src/ui/layout3d.c‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
/* ── Constants ────────────────────────────────────────────────── */
2626

27-
#define DEFAULT_MAX_NODES 2000
28-
#define HARD_MAX_NODES 200000
27+
#define DEFAULT_MAX_NODES 5000
28+
#define HARD_MAX_NODES 10000000
2929
#define BH_THETA 1.2f
3030
#define OCTREE_MAX_DEPTH 26 /* stop subdividing coincident points (OOM guard) */
3131
#define OCTREE_MIN_HALF 1e-4f /* minimum octree cell half-size */
@@ -173,26 +173,35 @@ static float rand_float(uint32_t *seed) {
173173
return (float)((*seed >> 16) & 0x7FFF) / 32768.0f - 0.5f;
174174
}
175175

176+
/* Ceiling for a caller-requested node budget. CBM_UI_MAX_RENDER_NODES lowers
177+
* (or raises, up to HARD_MAX_NODES) the ceiling for constrained deployments;
178+
* without it the full hard ceiling is available to explicit requests. */
176179
static int render_node_limit(void) {
177180
const char *raw = getenv("CBM_UI_MAX_RENDER_NODES");
178181
if (!raw || !raw[0]) {
179-
return DEFAULT_MAX_NODES;
182+
return HARD_MAX_NODES;
180183
}
181184
errno = 0;
182185
char *end = NULL;
183186
long v = strtol(raw, &end, 10);
184187
if (errno != 0 || end == raw || *end != '\0' || v <= 0) {
185-
return DEFAULT_MAX_NODES;
188+
return HARD_MAX_NODES;
186189
}
187190
if (v > HARD_MAX_NODES) {
188191
return HARD_MAX_NODES;
189192
}
190193
return (int)v;
191194
}
192195

196+
/* The default is a default, not a ceiling: an explicit request is honored up
197+
* to the (env-adjustable) ceiling; only a missing/invalid request falls back
198+
* to DEFAULT_MAX_NODES. */
193199
static int clamp_max_nodes(int requested) {
194200
int cap = render_node_limit();
195-
if (requested <= 0 || requested > cap) {
201+
if (requested <= 0) {
202+
requested = DEFAULT_MAX_NODES;
203+
}
204+
if (requested > cap) {
196205
return cap;
197206
}
198207
return requested;
@@ -317,7 +326,17 @@ typedef struct {
317326
/* ── Local optimization (gentle, anchor-preserving) ───────────── */
318327

319328
static void local_optimize(body_t *b, int n, const int *es, const int *ed, int ne) {
320-
for (int iter = 0; iter < LOCAL_ITERATIONS; iter++) {
329+
/* Scale iteration effort down for very large graphs: each iteration is
330+
* O(n log n) octree work, and past ~100k bodies the anchor layout already
331+
* dominates the visible structure — fewer refinement passes keep huge
332+
* budgets responsive instead of multiplying minutes of compute. */
333+
int iterations = LOCAL_ITERATIONS;
334+
if (n > 500000) {
335+
iterations = 10;
336+
} else if (n > 100000) {
337+
iterations = 20;
338+
}
339+
for (int iter = 0; iter < iterations; iter++) {
321340
for (int i = 0; i < n; i++) {
322341
b[i].fx = 0;
323342
b[i].fy = 0;

‎tests/test_ui.c‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,48 @@ TEST(layout_clamps_render_cap_from_env) {
358358
PASS();
359359
}
360360

361+
/* A caller-requested budget above the default must be honored (up to the hard
362+
* ceiling) when no env cap is set — the default is a default, not a ceiling. */
363+
TEST(layout_honors_budget_above_default) {
364+
cbm_store_t *store = cbm_store_open_memory();
365+
ASSERT_NOT_NULL(store);
366+
367+
const char *old_raw = getenv("CBM_UI_MAX_RENDER_NODES");
368+
char *old_cap = old_raw ? strdup(old_raw) : NULL;
369+
cbm_unsetenv("CBM_UI_MAX_RENDER_NODES");
370+
371+
cbm_store_upsert_project(store, "test", "/tmp/test");
372+
373+
enum { BUDGET_NODES = 5100 };
374+
for (int i = 0; i < BUDGET_NODES; i++) {
375+
char name[32], qn[64];
376+
snprintf(name, sizeof(name), "fn%d", i);
377+
snprintf(qn, sizeof(qn), "test::fn%d", i);
378+
cbm_node_t n = {.project = "test",
379+
.label = "Function",
380+
.name = name,
381+
.qualified_name = qn,
382+
.file_path = "a.c",
383+
.start_line = i,
384+
.end_line = i + 1};
385+
cbm_store_upsert_node(store, &n);
386+
}
387+
388+
cbm_layout_result_t *r =
389+
cbm_layout_compute(store, "test", CBM_LAYOUT_OVERVIEW, NULL, 0, BUDGET_NODES);
390+
ASSERT_NOT_NULL(r);
391+
ASSERT_EQ(r->node_count, BUDGET_NODES);
392+
ASSERT_EQ(r->total_nodes, BUDGET_NODES);
393+
394+
cbm_layout_free(r);
395+
cbm_store_close(store);
396+
if (old_cap) {
397+
cbm_setenv("CBM_UI_MAX_RENDER_NODES", old_cap, 1);
398+
free(old_cap);
399+
}
400+
PASS();
401+
}
402+
361403
TEST(layout_deterministic) {
362404
cbm_store_t *store = cbm_store_open_memory();
363405
ASSERT_NOT_NULL(store);
@@ -759,6 +801,7 @@ SUITE(ui) {
759801
RUN_TEST(layout_two_connected);
760802
RUN_TEST(layout_respects_max_nodes);
761803
RUN_TEST(layout_clamps_render_cap_from_env);
804+
RUN_TEST(layout_honors_budget_above_default);
762805
RUN_TEST(layout_deterministic);
763806
RUN_TEST(layout_to_json);
764807
RUN_TEST(layout_null_inputs);

0 commit comments

Comments
 (0)