Repository navigation
Closed
Labels
type/automationAutomation script, workflow, gh-aw, dependabot config.type/performanceLatency, throughput, memory, install time.
Description
Performance Scan - 2026-08-02
Automated scan of src/apm_cli/ for algorithmic performance anti-patterns.
2 finding(s) identified.
Findings
[B] Linear scan inside loop -- commands/uninstall/engine.py:472-504
- Current: O(packages * lockfile_size) -- for each package in the uninstall list, two sequential full scans of
lockfile.dependencies.values()are performed (first-pass exact match at line 483, second-pass plugin_name fallback at line 493). With a 200-package lockfile and 10 packages to uninstall, this is ~4,000 dict-value iterations. - Proposed: O(packages + lockfile_size) -- pre-build two lookup dicts from the lockfile once before the outer loop, then do O(1) lookups per package.
- Fix: Before the
for package in packagesloop, buildby_exact: dict[tuple[str,str], dep] = {(d.marketplace_plugin_name, d.discovered_via): d for d in lockfile.dependencies.values()}and a fallbackby_plugin: dict[str, dep]; replace both innerfor dep in lockfile.dependencies.values()scans with dict lookups.
[D] Repeated env-var reads inside nested loop -- registry/operations.py:380-401
- Current:
os.getenv(var_name)is called inside a triple-nested loop (outer: perserver_ref, middle: perpackage, inner: perenv_vardict entry). The same environment variable name can be read multiple times across server references, performing redundant syscalls on each iteration. - Proposed: O(1) per lookup after a single snapshot -- snapshot
os.environonce into a local dict before thefor server_ref in server_referencesloop and replaceos.getenv(var_name)withenv_snapshot.get(var_name). - Fix: Add
env_snapshot = dict(os.environ)before the loop at line 353 and replaceos.getenv(var_name)at line 393 withenv_snapshot.get(var_name).
Scan coverage
- src/apm_cli/ (425 files scanned)
- Patterns checked: A (quadratic loops), B (linear scan in loop),
C (unconditional expensive ops), D (redundant config parsing),
E (heavy top-level imports), F (sequential independent I/O)
Generated by Daily Performance Scanner · 61.8 AIC · ⌖ 6.18 AIC · ⊞ 7.3K · ◷
- expires on Aug 9, 2026, 1:45 AM UTC
Metadata
Metadata
Assignees
Labels
type/automationAutomation script, workflow, gh-aw, dependabot config.type/performanceLatency, throughput, memory, install time.
Type
Projects
- StatusShow more project fieldsDone
Activity