Skip to content

Commit f3754d6

Browse files
committed
docs(pipeline): CBM_EXTRACT_BUDGET is a CPU-time parse budget, not bytes (DeusData#2311)
The comment on CBM_EXTRACT_BUDGET called it a "maximum byte budget", but every call site passes it as cbm_extract_file*()'s timeout_micros, which cbm.c converts to nanoseconds and uses as a per-thread CPU-time deadline (5 s) with a 12x wall-clock ceiling as a backstop for a stuck parse. No code path uses the value with the wrong unit; only the documentation was wrong. Correct the constant's comment, and bring the timeout_micros description in cbm.h up to date (CPU time + wall backstop, not a plain timeout) and back onto cbm_extract_file(), from which later additions had separated it. No behavior change; the budget value is unchanged. Reported-by: BobbieBarker Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 64c23fa commit f3754d6

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎internal/cbm/cbm.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,9 +729,6 @@ const char *cbm_index_quarantine_phase(const char *rel_path);
729729
void cbm_index_mark_start(const char *rel_path);
730730
void cbm_index_mark_done(const char *rel_path);
731731

732-
// Extract all data from one file. Caller must call cbm_free_result().
733-
// source must remain valid for the duration of the call.
734-
// timeout_micros: per-file parse timeout in microseconds (0 = no timeout).
735732
/* Compact a finished result: copy everything reachable from it -- every
736733
* record array at exact count, every string once (interned by content within
737734
* the file), the retained source -- into one exact-size arena, and destroy the
@@ -767,6 +764,11 @@ void cbm_work_arena_keep_begin(void);
767764
/* Free the compaction scratch this thread kept (cbm_work_arena_release calls it). */
768765
void cbm_result_compact_release_thread(void);
769766

767+
// Extract all data from one file. Caller must call cbm_free_result().
768+
// source must remain valid for the duration of the call.
769+
// timeout_micros: per-file tree-sitter parse budget in microseconds of the
770+
// calling thread's CPU time, with a wall-clock backstop of
771+
// CBM_PARSE_WALL_CEILING_FACTOR x the budget (0 = no budget).
770772
CBMFileResult *cbm_extract_file(const char *source, int source_len, CBMLanguage language,
771773
const char *project, const char *rel_path, int64_t timeout_micros,
772774
const char **extra_defines, // NULL-terminated, or NULL

‎src/pipeline/pipeline_internal.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323

2424
/* ── Shared pipeline constants ─────────────────────────────────── */
2525

26-
/* Maximum byte budget for tree-sitter extraction per file */
26+
/* Per-file tree-sitter parse budget, in MICROSECONDS of this thread's CPU time
27+
* (5 s). Passed as cbm_extract_file*()'s timeout_micros; a generous wall-clock
28+
* ceiling (CBM_PARSE_WALL_CEILING_FACTOR x, ~60 s) backstops a stuck parse.
29+
* It is a time budget, not a byte budget. */
2730
#define CBM_EXTRACT_BUDGET 5000000
2831

2932
/* Route node QN buffer size (must fit __route__METHOD__/full/url/path) */

0 commit comments

Comments
 (0)