Skip to content

maint: speed up debug-build detection after signature v2#41

Merged
karngyan merged 1 commit into
mainfrom
maint/debug-detection-perf
Jul 18, 2026
Merged

maint: speed up debug-build detection after signature v2#41
karngyan merged 1 commit into
mainfrom
maint/debug-detection-perf

Conversation

@karngyan

Copy link
Copy Markdown
Contributor

Claim

Cold pattern detection is roughly 12x faster in debug builds after the signature-v2 change (ADR 0014), with byte-identical output. This is a build-profile change only — no source or behavior change.

Root cause

Signature normalization (autophagy_events::signature, added in #36) runs six regex::replace_all passes plus string churn over every tool command. In a fully unoptimized debug build, both the regex engine (a dependency) and the workspace's own normalizer/detector loops run slow, and they compound: normalization repeatedly crosses the boundary between our code and the regex crate. A cold detection pass over a 69,400-event history took ~138s in debug vs ~11s in release — about 3x slower than the pre-v2 debug experience and painful for test iteration.

The regexes were already compiled once via LazyLock, so recompilation was not the cause; the cost is raw unoptimized execution.

Fix

Add a dev-profile optimization in the root Cargo.toml:

  • [profile.dev.package."*"] opt-level = 2 — optimize all third-party dependencies (notably regex/regex-automata/aho-corasick). Deps change rarely, so this is a one-time build cost, not a per-edit cost.
  • [profile.dev.package.autophagy-events] and [profile.dev.package.autophagy-patterns] at opt-level = 2 — the workspace's own hot path (the normalizer and the detectors).

The rest of the workspace stays unoptimized, so incremental rebuilds of the crates under active development (e.g. autophagy-cli) stay fast.

Both parts are needed and are strongly super-additive (measured on the same 69k-event DB copy, debug):

Configuration Cold detection
baseline (nothing optimized) 138.3s
deps only ("*") 52.5s
hot workspace crates only 91.3s
both (this PR) 11.4s

Evidence

Same 69,400-event / 320-session database copy, patterns --recompute (cache bypassed), AUTOPHAGY_CONFIG_DIR pointed at a throwaway dir, user DB/config untouched:

Build Before After
debug 138.3s 11.4s
release 10.7s 10.7s (unchanged — release profile untouched)

Identical-output proof: autophagy --output json patterns --recompute produces byte-identical JSON before and after (69,400 events scanned, 710 candidate signatures, same findings), verified with diff <(jq -S .) <(jq -S .). Debug and release outputs also match each other.

mise run check passes fully (fmt + lint + test + docs + ci).

Privacy

None. This is a compiler optimization-level change to the dev profile only. No new data is read, persisted, or transmitted; detection output is unchanged.

🤖 Generated with Claude Code

Cold detection over a large history was ~138s in a debug build versus
~11s in release. Signature normalization (ADR 0014) runs several regex
passes over every tool command, and in a fully unoptimized build both the
regex engine and the workspace's own normalizer/detector code run slow.

Optimize third-party dependencies (`opt-level = 2`) plus the two hot
workspace crates (`autophagy-events`, `autophagy-patterns`) in the dev
profile. The rest of the workspace stays unoptimized so incremental
rebuilds during development remain fast. No source or behavior change;
detection output is byte-identical.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@karngyan
karngyan merged commit 51c157c into main Jul 18, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant