Analyzer Architecture (alnoms.core.analyzer)
The Analyzer is the central orchestrator of the Alnoms Performance Intelligence Engine. It coordinates dynamic profiling, static AST analysis, empirical scaling tests, and prescriptive remediation into a single deterministic governance pipeline.
๐งฉ 1. The Intelligence Layers
The Analyzer unifies four independent intelligence layers to provide a 360-degree view of system performance:
- Dynamic Profiling: Identifies the empirical bottlenecks in developer-defined functions.
- Static Intent Analysis: Scans the Abstract Syntax Tree (AST) to detect structural anti-patterns.
- Empirical Scaling Tests: Optional doubling tests that provide mathematical proof of complexity.
- Prescriptive Remediation: Maps bottlenecks to "Sovereign" data structures for actionable cures.
๐ 2. The Execution Pipeline
The Analyzer executes a stateless, side-effect-free pipeline to produce a unified governance report.
- Script Execution: Loads the target script in an isolated namespace to prevent global state pollution.
- Dynamic Profiling: Extracts the top 5 slowest functions using
cProfileto identify real-world bottlenecks. - Static AST Analysis: Identifies patterns (e.g., membership tests) and calculates Loop Depth (\(O(N^d)\)).
- Empirical Scaling Test: (Optional) Executes doubling tests (\(N, 2N, 4N\)) to verify asymptotic behavior.
- Decision Engine: Synthesizes metadata to recommend the most efficient DSA model.
- Fixer Integration: Generates "Before/After" remediation snippets.
- Governance Report: Compiles all data into a deterministic final output.
โ๏ธ 3. Internal Mechanics
3.1 Loop Depth Logic
The Analyzer computes complexity by recursively descending into nested loops while ignoring comprehensions (which are optimized at the C-level). It pinpoints the loop closest to the detected pattern to estimate Static Complexity: $\(O(N^{\text{depth}})\)$
3.2 The Doubling Test (Empirical Truth)
When deep=True is enabled, the Analyzer moves beyond static estimates. It performs repeated trials with increasing input sizes to calculate the Scaling Ratio. This is the "empirical truth" that validates whether a theoretical \(O(N^2)\) pattern is actually causing a quadratic slowdown in the current environment.
3.3 Prescriptive Remediation
Unlike traditional profilers that offer vague advice, the Analyzer's Fixer integration is prescriptive. It provides:
* The Cure: The specific implementation from alnoms.dsa.
* The Impact: Estimated performance gain (e.g., \(100\times - 1000\times\)).
* The Proof: A complexity shift explanation (e.g., \(O(N^2) \rightarrow O(N)\)).
๐งญ 4. Design Principles
The Analyzer is built on the Arprax Lab standard for industrial-grade software:
- Determinism: No randomness. The same code on the same hardware produces the same diagnostic.
- Transparency: Every performance claim is backed by observable measurements.
- Minimal Cognitive Tax: Fixes are designed to be "drop-in" ready, reducing the burden on the developer.
- Governance Over Profiling: The end goal is not just to see where time is spent, but to enforce a performance standard that prevents silent failures at scale.
๐งช 5. Example Output
Given a script with a membership test inside a nested loop, the Analyzer produces:
* Static Intent: Membership test inside loop.
* Loop Depth: 2.
* Empirical Ratio: ~4.0 (Quadratic).
* Verdict: โ ๏ธ WARNING: Function operates at \(O(N^2)\).
* Remediation: Replace list-lookup with SeparateChainingHashST.
๐ Next Step: Explore how the Decision Engine selects the perfect data structure for your specific bottleneck.