maint: speed up debug-build detection after signature v2#41
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 sixregex::replace_allpasses plus string churn over every tool command. In a fully unoptimized debug build, both theregexengine (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 (notablyregex/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]atopt-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):
"*")Evidence
Same 69,400-event / 320-session database copy,
patterns --recompute(cache bypassed),AUTOPHAGY_CONFIG_DIRpointed at a throwaway dir, user DB/config untouched:Identical-output proof:
autophagy --output json patterns --recomputeproduces byte-identical JSON before and after (69,400 events scanned, 710 candidate signatures, same findings), verified withdiff <(jq -S .) <(jq -S .). Debug and release outputs also match each other.mise run checkpasses 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