Skip to content

[perf-scan] 2026-08-02 -- performance opportunities found #2425

Closed

Description

@github-actions

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 packages loop, build by_exact: dict[tuple[str,str], dep] = {(d.marketplace_plugin_name, d.discovered_via): d for d in lockfile.dependencies.values()} and a fallback by_plugin: dict[str, dep]; replace both inner for 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: per server_ref, middle: per package, inner: per env_var dict 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.environ once into a local dict before the for server_ref in server_references loop and replace os.getenv(var_name) with env_snapshot.get(var_name).
  • Fix: Add env_snapshot = dict(os.environ) before the loop at line 353 and replace os.getenv(var_name) at line 393 with env_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

Activity

  1. added
    type/automation
    type/performance
    on Aug 2, 2026
  2. moved this from Todo to In Progress in APM Roadmapon Aug 4, 2026
  3. moved this from In Progress to Done in APM Roadmapon Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/automationtype/performance

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions