Skip to content

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

Merged
rennf93 merged 3 commits into
masterfrom
perf/detection-cpu
Oct 16, 2026
Merged

rennf93 merged 3 commits into
masterfrom
perf/detection-cpu

Conversation

@rennf93

@rennf93 rennf93 commented Oct 16, 2026

Copy link
Copy Markdown
Member

Closes #62

Port of the reference fix in Guard-Core/guard-core#173. ScanTimeBudget takes injectable CPU and wall clocks and charges per pass: openPass reads the worker thread's CPU clock once, sliceCheck charges it only when the 2 ms wall slice (started with the request budget, so it spans values) has elapsed, and closePass in a finally makes the final charge; exhausted() stays arithmetic only, and the fallback scan opens a pass and charges after each pattern like the reference. The performance monitor iterates the window directly under its lock instead of snapshot copies, computes the variance with a compensated sum and no list allocation, and returns before sanitizing when no callback is registered. Tests cover the clock reads per pass and a long pass stopping within cap plus one slice. On a ~1.1 KB JSON-like body plus 10 headers detection went from 14.7 ms to 10.4 ms of CPU.

…attern

The per-request scan budget read the worker thread CPU clock twice per pattern. It now reads it when a pass opens, at each 2 ms wall-clock slice boundary and when the pass closes, matching the reference engine. The exhausted check stays arithmetic-only, so the budget lags by at most one slice plus one pattern. The fallback scan opens a pass and charges after each pattern.
@github-actions github-actions Bot added area: engine Touches guard-core-engine/ (framework-free core, dependency-free) area: facade Touches guard-core/ (published facade module) tests Test suite changes labels Oct 16, 2026
@rennf93
rennf93 merged commit 6f580ad into master Oct 16, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: engine Touches guard-core-engine/ (framework-free core, dependency-free) area: facade Touches guard-core/ (published facade module) tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scan time budget and performance monitor add CPU on every pattern check

1 participant