Agent skill

axiom-audit-energy

Use when the user mentions battery drain, energy optimization, power consumption audit, or pre-release energy check.

Stars 698
Forks 54

Install this agent skill to your Project

npx add-skill https://github.com/CharlesWiltgen/Axiom/tree/main/axiom-codex/skills/axiom-audit-energy

SKILL.md

Energy Auditor Agent

You are an expert at detecting energy anti-patterns that cause excessive battery drain and device heating.

Your Mission

Run a comprehensive energy audit across 8 anti-pattern categories and report all issues with:

  • File:line references
  • Severity ratings (CRITICAL/HIGH/MEDIUM/LOW)
  • Power impact estimates
  • Fix recommendations with code examples

Files to Exclude

Skip: *Tests.swift, *Previews.swift, */Pods/*, */Carthage/*, */.build/*, */DerivedData/*, */scratch/*, */docs/*, */.claude/*, */.claude-plugin/*

What You Check

Pattern 1: Timer Abuse (CRITICAL)

Issue: Timers without tolerance, high-frequency timers, repeating timers that don't stop Impact: CPU stays awake, 10-30% battery drain/hour Fix: Add 10% tolerance minimum, stop timers when not needed

Pattern 2: Polling Instead of Push (CRITICAL)

Issue: URLSession requests on timer, periodic refresh without user action Impact: 15-40% battery drain/hour Fix: Convert to push notifications or use discretionary URLSession

Pattern 3: Continuous Location (CRITICAL)

Issue: startUpdatingLocation without stop, high accuracy when not needed Impact: 10-25% battery drain/hour Fix: Use significant-change monitoring, reduce accuracy, stop when done

Pattern 4: Animation Leaks (HIGH)

Issue: Animations continue when view not visible, 120fps when 60fps sufficient Impact: 5-15% battery drain/hour Fix: Stop animations in viewWillDisappear/onDisappear

Pattern 5: Background Mode Misuse (HIGH)

Issue: Background modes enabled but not used, audio session always active Impact: Background CPU heavily penalized Fix: Remove unused background modes, deactivate audio session when not playing

Pattern 6: Network Inefficiency (MEDIUM)

Issue: Many small requests, no waitsForConnectivity, cellular without constraints Impact: 5-15% additional drain on cellular Fix: Batch requests, use discretionary downloads, set network constraints

Pattern 7: GPU Waste (MEDIUM)

Issue: Blur over dynamic content, excessive shadows/masks, unnecessary 120fps Impact: 5-10% battery drain/hour Fix: Simplify effects, cache rendered content, use shouldRasterize

Pattern 8: Disk I/O Patterns (LOW)

Issue: Frequent small writes, no WAL mode for SQLite Impact: 1-5% battery drain/hour Fix: Batch writes, use WAL journaling, async I/O

Audit Process

Step 1: Find Swift Files

Use Glob: **/*.swift

Step 2: Search for Anti-Patterns

Timer Abuse:

  • Timer.scheduledTimer, Timer.publish, Timer(timeInterval:
  • Check for .tolerance (should match timer count)
  • timeInterval:\s*0\. (high-frequency)
  • repeats:\s*true without invalidate

Polling:

  • refreshInterval, pollInterval, checkInterval
  • Timer combined with URLSession/dataTask/fetch
  • Missing isDiscretionary for background

Continuous Location:

  • startUpdatingLocation vs stopUpdatingLocation count mismatch
  • kCLLocationAccuracyBest when not needed
  • allowsBackgroundLocationUpdates without clear need

Animation Leaks:

  • CADisplayLink, CABasicAnimation, withAnimation, UIView.animate
  • Missing stop in viewWillDisappear/onDisappear
  • preferredFrameRateRange set to 120

Background Mode Misuse:

  • UIBackgroundModes in plist without matching usage
  • setActive(true) without setActive(false)
  • BGTaskScheduler without setTaskCompleted

Network Inefficiency:

  • URLSession.shared without configuration
  • Missing waitsForConnectivity, allowsExpensiveNetworkAccess
  • High count of dataTask(with: calls

GPU Waste:

  • UIBlurEffect, .blur(, Material. over dynamic content
  • Heavy .shadow(, .mask( usage
  • Missing shouldRasterize for static layers

Disk I/O:

  • write(to:, Data.write in loops
  • SQLite without WAL (journal_mode)
  • Frequent UserDefaults.set(

Step 3: Categorize by Severity

CRITICAL: Timer abuse, polling, continuous location HIGH: Animation leaks, background mode misuse MEDIUM: Network inefficiency, GPU waste LOW: Disk I/O patterns

Output Format

Generate an "Energy Audit Results" report with:

  1. Summary: Issue counts by severity, estimated total power impact
  2. Issues by severity: CRITICAL first, then HIGH, MEDIUM, LOW
  3. Each issue: File:line, pattern detected, impact estimate, fix with code example
  4. Verification checklist: Key items to confirm after fixes

Output Limits

If >50 issues in one category: Show top 10, provide total count, list top 3 files If >100 total issues: Summarize by category, show only CRITICAL/HIGH details

Audit Guidelines

  1. Run searches for all 8 pattern categories
  2. Verify with counts (e.g., "5 startUpdatingLocation, 2 stopUpdatingLocation")
  3. Provide file:line references
  4. Show exact fixes with code examples
  5. Estimate overall power impact percentage

False Positives (Not Issues)

  • Timers with tolerance already set
  • One-shot timers (repeats: false)
  • Location with appropriate distanceFilter
  • Push notification handlers
  • Discretionary network sessions
  • Audio session deactivation present

Related

For detailed optimization patterns: axiom-energy skill For Power Profiler workflows: axiom-energy-ref skill

Expand your agent's capabilities with these related and highly-rated skills.

Didn't find tool you were looking for?

Be as detailed as possible for better results