Skip to content

perf(detection): charge the scan budget per pass and cut monitor overhead - #158

Merged
rennf93 merged 1 commit into
masterfrom
perf/detection-cpu
Oct 16, 2026
Merged

rennf93 merged 1 commit into
masterfrom
perf/detection-cpu

Conversation

@rennf93

@rennf93 rennf93 commented Oct 16, 2026

Copy link
Copy Markdown
Member

Closes #157

Port of the reference fix in Guard-Core/guard-core#173. ScanTimeBudget charges CPU per pass: open_pass reads the thread CPU clock once, tick reads only a cheap monotonic clock per pattern and charges the CPU clock when 2 ms have elapsed, and close_pass makes the final charge; the slice spans passes, exhausted() stays arithmetic only, and the wall-clock fallback stays for platforms without a thread CPU clock. Tests cover the clock reads per pass and a long pass stopping within one slice of the cap. On a ~1 KB JSON-like value plus 10 short header values detect went from 6.54 ms to 6.37 ms (release build); regex execution dominates the Rust cost, so the gain is small.

…attern

The per-request scan time budget read the thread CPU clock around every pattern. It now charges per pass: one read when a pass opens, one at each 2 ms wall-clock slice boundary and one when the pass closes. The per-pattern check reads only a cheap monotonic clock and compares the charged total, so the budget lags the true spend by at most one slice plus one pattern.
@github-actions github-actions Bot added the area: engine Touches crates/guard-core-engine/ (compiler, preprocessor, semantic, detect, patterns) label Oct 16, 2026
@rennf93
rennf93 merged commit 96e5d57 into master Oct 16, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: engine Touches crates/guard-core-engine/ (compiler, preprocessor, semantic, detect, patterns)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scan time budget reads the thread CPU clock twice per pattern check

1 participant