Skip to content

[perf-scan] 2026-08-15 -- performance opportunities found #2575

Description

@github-actions

Performance Scan - 2026-08-15

Automated scan of src/apm_cli/ for algorithmic performance anti-patterns.
2 finding(s) identified.

Findings

[A] Double-pass over refs in sort_remote_refs -- deps/git_remote_ops.py:105-111

  • Current: O(2n) -- refs list iterated twice via separate list comprehensions to partition tags and branches; called once per dependency resolution (git-hosted deps)
  • Proposed: O(n) -- single-pass loop partitions refs into tags and branches simultaneously
  • Fix: Replace the two comprehensions at lines 107-108 with a single for r in refs loop that appends to tags or branches based on r.ref_type, eliminating the second full traversal.

[E] Full install stack eagerly imported on every CLI invocation -- cli/cli.py:27-56

  • Current: cli.py imports all 20+ command modules (including commands/install.py) unconditionally at startup; commands/install.py transitively pulls in the entire install subtree (~18 000 lines across 30+ modules); lightweight subcommands such as apm config, apm doctor, and apm list bear the full import cost every run
  • Proposed: Lazy command-module loading so each commands/*.py file is imported only when its subcommand is actually invoked
  • Fix: Replace the flat module-level imports in cli.py with a Click lazy-loading group (e.g. click.Group subclass that defers __import__ per command) so that apm config get key does not load the install, marketplace, or compile stacks.

Scan coverage

  • src/apm_cli/ (430 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 · 121 AIC · ⌖ 6.22 AIC · ⊞ 7.3K ·

  • expires on Aug 22, 2026, 1:43 AM UTC

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/automationAutomation script, workflow, gh-aw, dependabot config.type/performanceLatency, throughput, memory, install time.

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions