agentleFS
muon-m2muon-m2/magento2-tools/skills/perf-audit/SKILL.md

perf-audit

Skill6 starsChanged 28 days agoMITView on GitHub

Static analysis (N+1 patterns, missing cache identities, expensive plugins) with optional runtime inspection (indexer status, cache hit rates, slow queries, queue backlog). - Static-first. Default pass uses only the source tree — no runtime, no Magento CLI required. - Runtime is opt-in. Phase 3 runs only when the user passes --runtime. - Severity by impact at scale. A 50ms ViewModel call in a non-storefront context is Low; an N+1 query in checkout is High. - Concrete recommendation. Every finding includes…

We split this skill into the rules it gives an agent

6 rules. 0 are common, 3 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 9 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Static-first: Default pass uses only the source tree — no runtime, no Magento CLI required.

    line 20
  2. Distinctive:

    Concrete recommendation: Every finding includes the specific replacement pattern, not "improve performance."

    line 25
  3. Distinctive:

    Only if user authorizes AND Magento CLI is present:

    line 62
  4. Very specific:

    If BLACKFIRE_* env vars or ~/.blackfire.ini present:

    line 83
  5. Very specific:

    Default: auto — agents when the plugin's context-budget hook reports this conversation above its threshold, inline otherwise.

    line 182
  6. Very specific:

    Use the shared five-point scale (context/references/severity.md) with the performance-specific calibration anchors, the storefront-vs-admin …

    line 192

“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Magento 2 Performance Audit

Static analysis (N+1 patterns, missing cache identities, expensive plugins) with optional runtime inspection (indexer status, cache hit rates, slow queries, queue backlog).

Core Rules

  • Static-first. Default pass uses only the source tree — no runtime, no Magento CLI required.
  • Runtime is opt-in. Phase 3 runs only when the user passes --runtime.
  • Severity by impact at scale. A 50ms ViewModel call in a non-storefront context is Low; an N+1 query in checkout is High.
  • Concrete recommendation. Every finding includes the specific replacement pattern, not "improve performance."
  • JSON + SARIF. Same shape as review.

Workflow

Phase 0 — Context Resolution

Invoke context. Note presence of Magento CLI, Redis CLI, DB CLI, Blackfire.

Phase 1 — Scope

  • Single module → static analysis only by default; runtime opt-in.
  • Multiple modules → static analysis across all; runtime opt-in.
  • Site-wide → static across all custom modules + runtime checks.

Phase 2 — Static Pass

Per references/perf-checklist.md:

CheckPattern
N+1 in foreachRepository / Factory call inside loop body
Full-collection loadgetCollection() without addFieldToFilter / setPageSize
Expensive constructor workDB / HTTP / external call in __construct
Missing cache identityBlock subclass without getIdentities()
Missing cache lifetimeBlock subclass without getCacheLifetime()
around plugin on hot pathCatalog / Quote / Order method intercepted
Synchronous external HTTP in storefrontCurl / Client in Block, ViewModel, Resolver
Cron job without batchforeach ($collection as $item) in cron with no setPageSize
Queue consumer without batchSingle-message processing pattern
Plugin without sortOrderOrder-sensitive plugin chain

Run via ${CLAUDE_SKILL_DIR}/scripts/static-perf.sh <module-path>.

Phase 3 — Runtime Pass (Opt-in)

Only if user authorizes AND Magento CLI is present:

CheckCommand
Indexer status{magento_cli} indexer:status
Indexer mode{magento_cli} indexer:show-mode
Pending cronDB query on cron_schedule
Queue backlog{magento_cli} queue:consumers:list + RabbitMQ stats
Cache type status{magento_cli} cache:status
Slow queriesMySQL slow log — resolve the path via SHOW VARIABLES LIKE 'slow_query_log_file'; only when slow_query_log is ON
Redis hit rateredis-cli INFO stats
Varnish statusCurl headers

${CLAUDE_SKILL_DIR}/scripts/runtime-checks.sh automates the tool-based probes (indexer, cache, queue, Redis) and emits them as findings. The DB (pending cron), slow-log, and Varnish rows are run manually when their source is reachable — the script does not emit a slow_query finding, so do not claim a slow-query result unless the slow log was actually read.

Phase 4 — Optional: Blackfire / Tideways Integration

If BLACKFIRE_* env vars or ~/.blackfire.ini present:

  • Prompt user to run a profiled URL.
  • Parse Blackfire profile JSON.
  • Surface top 10 hotspots with file:line references.

Phase 5 — Report

Two automation artifacts and one LLM deliverable:

  1. JSON + SARIF (automated). ${CLAUDE_SKILL_DIR}/scripts/build-findings.sh aggregates static-perf.sh (always) and runtime-checks.sh (when INCLUDE_RUNTIME=1), invokes the shared emitter with OUTPUT_KIND=performance, and writes both .json and .sarif.
  2. Markdown summary (LLM deliverable, NOT automated). Written by the skill in the conversation, ranked by impact, with concrete recommendations. Sample:

    ### High — Catalog\Block\Category::getProducts() N+1 on store frontend
    
    Impact: Each category page render triggers 1+N queries (N = product count).
    Evidence: src/app/code/Acme/Catalog/Block/Category.php:47
    Recommendation: Use addAttributeToSelect(['name','price']) before iteration; or use
    the CollectionProcessor pattern.
    Verification: Re-render the page with debug toolbar; query count should drop from
    1+N to 1.

Builder invocation (for reference; callers normally just run the skill):

TARGET_MODULE=<Vendor_Module|site> TARGET_PATH=<path> SCOPE=module \
SCAN_ROOT={ctx.magento_root}/app/code INCLUDE_RUNTIME=0 \
DOCS_ROOT="${DOCS_ROOT_ARG:-.docs}" \
bash ${CLAUDE_SKILL_DIR}/scripts/build-findings.sh

where DOCS_ROOT_ARG is the resolved --docs-root value (empty ⇒ default .docs).

Inputs

/perf-audit [--runtime] [--scope=module|site] [--docs-root=<path>] [<Vendor>_<Module>...]

Flags:

  • --runtime — opt in to runtime checks (Phase 3, 4)
  • --scope=site — audit all custom modules + runtime
  • --format=markdown|json|sarif — output format
  • --docs-root=<path> — output-root override; see "Output Root" below

Outputs

Module scope (basename uses the underscore module name, e.g. Acme_OrderExport):

{output_root}/audits/{Vendor}_{Module}-perf-{date}.json    # automation artifact (build-findings.sh)
{output_root}/audits/{Vendor}_{Module}-perf-{date}.sarif   # automation artifact (build-findings.sh)
{output_root}/audits/{Vendor}_{Module}-perf-{date}.md      # LLM deliverable, written in Phase 5

Site scope:

{output_root}/audits/perf-{scope}-{date}.json
{output_root}/audits/perf-{scope}-{date}.sarif
{output_root}/audits/perf-{scope}-{date}.md

{output_root} (.docs by default, {ctx.docs_root}) is anchored at the project root, never under {ctx.magento_root}, app/code, or a module dir. See the Artifact location rule in context/SKILL.md and the --docs-root/DOCS_ROOT recipe in context/references/artifact-layout.md.

Output root (--docs-root)

This skill accepts --docs-root=<path> (see context/references/artifact-layout.md). When set, run the emitter with DOCS_ROOT=<path> so artifacts land under <path>/audits/; otherwise they default to {ctx.docs_root}/audits/. Orchestrators such as feature pass this to collect a run's artifacts under one folder.

Reference Files

  • references/perf-checklist.md — full static-check catalogue.
  • references/n-plus-one-patterns.md — known N+1 patterns + remediation.
  • references/caching-rules.md — identity, lifetime, tag rules.
  • references/indexer-health.md — indexer mode interpretation.
  • references/queue-health.md — backlog thresholds, dead-letter handling.
  • references/blackfire-integration.md — Blackfire profile parsing.
  • references/severity-perf.md — severity calibration anchored to shared scale.

Scripts

  • ${CLAUDE_SKILL_DIR}/scripts/static-perf.sh — static pattern scan over module sources.
  • ${CLAUDE_SKILL_DIR}/scripts/runtime-checks.sh — bin/magento + redis-cli + mysql probes.
  • ${CLAUDE_SKILL_DIR}/scripts/build-findings.sh — aggregate scanner output; emit JSON + SARIF via the shared context/scripts/emit-findings.sh pipeline. Structurally identical to security/scripts/build-findings.sh.
  • context/references/findings-schema.md — JSON findings-document structure the emitted .json conforms to (outputKind=performance).

Execution Mode

Default: auto — agents when the plugin's context-budget hook reports this conversation above its threshold, inline otherwise. In agents mode (--agents flag, or execution_mode in .claude/m2.json surfaced as {ctx.execution_mode} — selection contract in context/references/execution-modes.md) the judgement passes of this skill are dispatched to the read-only reviewer agent with a performance/operations dimension brief, and this skill owns synthesis. The scripted scanners (scripts/build-findings.sh) are deterministic and run identically in both modes.

Severity

Use the shared five-point scale (context/references/severity.md) with the performance-specific calibration anchors, the storefront-vs-admin bias, and the profile-backed severity bands in references/severity-perf.md.

Acceptance Criteria

  • Runs without Magento CLI; produces static report only.
  • Runtime checks gracefully degrade when tools are missing.
  • Top-10 findings are actionable with file:line + recommendation.
  • JSON output usable in CI for trend detection.

Related Skills

PhaseSkill
0context
(none for findings — output is the deliverable)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.