Skip to content

[perf-scan] 2026-08-20 -- performance opportunities found #2633

Description

@github-actions

Performance Scan - 2026-08-20

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

Findings

[B] Linear scan in loop (set/dict opportunity) -- bundle/lockfile_enrichment.py:150

direct = [f for f in deployed_files if any(f.startswith(p) for p in prefixes)]
  • Current: O(n x m) -- Python-level generator iterates over each prefix for every file in deployed_files (n = deployed files, m = target prefixes). On a package with hundreds of deployed files and several active targets the inner generator executes thousands of Python-level iterations.
  • Proposed: O(n) effective -- str.startswith(tuple) dispatches to a single C-level loop, eliminating the per-file Python generator overhead.
  • Fix: Replace any(f.startswith(p) for p in prefixes) with f.startswith(tuple(prefixes)) on line 150. The prefixes list is already built before the comprehension so no additional pre-computation is needed.

Context: _filter_files_by_target is called during apm pack for every exported bundle target, making this a hot path for projects with many deployed files.

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)

Notes:

  • Pattern C: http_cache already uses a tracked-size fast-path before os.walk in _enforce_size_cap -- no finding.
  • Pattern A: context_optimizer nested loops are guarded by _pattern_cache and _glob_cache -- no finding.
  • Pattern D: registry/operations.py os.getenv calls inside _prompt_for_environment_variables are one-shot per invocation -- no finding.
  • Pattern E: commands/install.py imports are all used at module scope for the install command surface -- no finding.
  • Pattern F: subprocess calls in bare_cache.py and git_cache.py are per-package single-operation calls, not independent-iteration loops -- no finding.

Generated by Daily Performance Scanner · 78.4 AIC · ⌖ 6.27 AIC · ⊞ 7.3K ·

  • expires on Aug 27, 2026, 1:39 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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions