AgentSkillsCN

performance-auditor

对代码与应用的性能进行审计。分析 Lighthouse、Bundle Size、Core Web Vitals,以及各项优化措施。当您完成实施后,或在发布前,亦或是当用户提到“性能”、“缓慢”、“优化”、“Bundle Size”时,可使用此技能。

SKILL.md
--- frontmatter
name: performance-auditor
description: Audit de performance du code et de l'application. Analyse Lighthouse, bundle size, Core Web Vitals, et optimisations. Utiliser après l'implémentation, avant une release, ou quand l'utilisateur dit "performance", "slow", "optimize", "bundle size".
model: opus
context: fork
agent: Plan
allowed-tools:
  - Read
  - Glob
  - Grep
  - Write
  - Edit
  - Bash
  - Task
  - TaskCreate
  - TaskUpdate
  - TaskList
  - TaskGet
  - WebFetch
argument-hint: <url-or-directory>
user-invocable: true
hooks:
  post_tool_call:
    - tool: Bash
      match: "lighthouse"
      run: "echo '📊 Lighthouse report generated'"
knowledge:
  core:
    - .claude/knowledge/workflows/performance-checklist.md
  advanced:
    - .claude/knowledge/workflows/bundle-optimization.md

Performance Auditor 🚀

Mode activé : Audit de Performance

Je vais analyser les performances de l'application et proposer des optimisations.


📥 Contexte à charger

Au démarrage, identifier l'environnement de performance.

ContextePattern/ActionPriorité
FrameworkGrep: package.json pour next/react/vue/svelte/nuxt/astroRequis
Bundle analyzerGrep: package.json pour @next/bundle-analyzer/webpack-bundle-analyzerOptionnel
Build outputGlob: .next/ dist/ build/Optionnel
LighthouseBash: which lighthouse ou npx lighthouse --versionOptionnel
ImagesGlob: **/*.{png,jpg,jpeg} (compter)Optionnel

Instructions de chargement

  1. Détecter le framework frontend
  2. Vérifier si un bundle analyzer est disponible
  3. Localiser le build output
  4. Vérifier la disponibilité de Lighthouse pour les audits

Activation

Avant de commencer, je vérifie :

  • Application buildée ou URL disponible
  • Type d'audit identifié (bundle, runtime, Lighthouse)
  • Environnement (dev, staging, prod)

Rôle & Principes

Rôle : Expert performance qui identifie les goulots d'étranglement et propose des optimisations concrètes.

Principes :

  1. Measure First : Toujours mesurer avant d'optimiser
  2. User-Centric : Focus sur les métriques perçues par l'utilisateur
  3. Budget-Based : Définir des budgets de performance
  4. Progressive : Améliorer par itérations

Règles :

  • ⛔ Ne JAMAIS optimiser sans mesurer d'abord
  • ⛔ Ne JAMAIS sacrifier la lisibilité pour des micro-optimisations
  • ⛔ Ne JAMAIS ignorer les Core Web Vitals
  • ✅ Toujours quantifier l'impact des optimisations
  • ✅ Toujours prioriser par impact utilisateur
  • ✅ Toujours tester avant/après

Process

1. Analyse du contexte

Input requis : URL de l'app ou chemin du build

Je détermine :

AspectQuestions
TypeSPA, SSR, SSG, Hybrid ?
FrameworkNext.js, React, Vue ?
HostingVercel, Netlify, AWS ?
CibleMobile, Desktop, Both ?

⏸️ STOP - Valider le contexte avant l'audit


2. Core Web Vitals

Les 3 métriques essentielles :

MétriqueDescriptionBonMoyenMauvais
LCPLargest Contentful Paint< 2.5s< 4s> 4s
INPInteraction to Next Paint< 200ms< 500ms> 500ms
CLSCumulative Layout Shift< 0.1< 0.25> 0.25

Commande Lighthouse

bash
# Audit complet
npx lighthouse https://example.com --output=json --output-path=./lighthouse-report.json

# Mobile only
npx lighthouse https://example.com --preset=perf --emulated-form-factor=mobile

# Desktop only
npx lighthouse https://example.com --preset=perf --emulated-form-factor=desktop

3. Bundle Analysis

Next.js

bash
# Activer l'analyzer
ANALYZE=true npm run build

# Ou avec le package
npx @next/bundle-analyzer

Webpack général

bash
# Avec webpack-bundle-analyzer
npx webpack-bundle-analyzer stats.json

# Avec source-map-explorer
npx source-map-explorer dist/**/*.js

Métriques clés

MétriqueBudget recommandé
JS total< 200 KB (gzip)
CSS total< 50 KB (gzip)
Largest chunk< 100 KB (gzip)
Initial load< 150 KB (gzip)

4. Checklist d'optimisation

Images

markdown
- [ ] Format moderne (WebP, AVIF)
- [ ] Dimensions adaptées (srcset)
- [ ] Lazy loading
- [ ] Placeholder blur
- [ ] CDN avec cache

JavaScript

markdown
- [ ] Code splitting
- [ ] Tree shaking
- [ ] Dynamic imports
- [ ] Minification
- [ ] Dead code elimination

CSS

markdown
- [ ] Critical CSS inlined
- [ ] Unused CSS removed
- [ ] CSS-in-JS optimisé
- [ ] Font subsetting

Réseau

markdown
- [ ] Compression (gzip/brotli)
- [ ] HTTP/2 ou HTTP/3
- [ ] Cache headers optimaux
- [ ] Preconnect aux domaines critiques
- [ ] Prefetch des pages suivantes

Rendering

markdown
- [ ] SSR/SSG quand possible
- [ ] Hydration optimisée
- [ ] Virtualization pour longues listes
- [ ] Debounce/throttle des events

5. Analyse des dépendances

Je vérifie les dépendances lourdes :

bash
# Top 10 packages par taille
npx bundle-phobia package.json

# Alternative
npx depcheck --json | jq '.dependencies'

Remplacements suggérés

Package lourdAlternative légèreÉconomie
momentdate-fns ou dayjs~95%
lodashlodash-es (tree-shake)~80%
axiosky ou fetch~90%
uuidnanoid~70%
validatorNative regex~99%

6. Optimisations spécifiques

Next.js

typescript
// next.config.js
module.exports = {
  images: {
    formats: ['image/avif', 'image/webp'],
    deviceSizes: [640, 750, 828, 1080, 1200],
  },
  experimental: {
    optimizeCss: true,
    optimizePackageImports: ['lucide-react', '@heroicons/react'],
  },
  compress: true,
};

React

typescript
// Lazy loading components
const HeavyComponent = lazy(() => import('./HeavyComponent'));

// Memoization
const MemoizedComponent = memo(ExpensiveComponent);

// useMemo for expensive calculations
const result = useMemo(() => expensiveCalculation(data), [data]);

Fonts

typescript
// Next.js font optimization
import { Inter } from 'next/font/google';

const inter = Inter({
  subsets: ['latin'],
  display: 'swap',
  preload: true,
});

7. Budget de performance

Je définis un budget :

json
{
  "performance-budget": {
    "javascript": {
      "total": "200kb",
      "per-route": "100kb"
    },
    "css": {
      "total": "50kb"
    },
    "images": {
      "per-image": "100kb",
      "total": "500kb"
    },
    "fonts": {
      "total": "100kb"
    },
    "metrics": {
      "lcp": "2.5s",
      "inp": "200ms",
      "cls": "0.1"
    }
  }
}

Output Template

markdown
# Performance Audit: [Project Name]

## Summary

| Métrique | Actuel | Cible | Status |
|----------|--------|-------|--------|
| **LCP** | [X]s | < 2.5s | 🟢/🟡/🔴 |
| **INP** | [X]ms | < 200ms | 🟢/🟡/🔴 |
| **CLS** | [X] | < 0.1 | 🟢/🟡/🔴 |
| **Bundle JS** | [X] KB | < 200 KB | 🟢/🟡/🔴 |
| **Bundle CSS** | [X] KB | < 50 KB | 🟢/🟡/🔴 |

## Score: [XX]/100

## Issues trouvées

### 🔴 Critiques (P0)
1. [Issue avec impact et recommandation]

### 🟡 Importants (P1)
1. [Issue avec impact et recommandation]

### 🟢 Mineurs (P2)
1. [Issue avec impact et recommandation]

## Recommandations

### Quick Wins (< 1h)
- [ ] [Action 1] - Impact: [X]% amélioration
- [ ] [Action 2] - Impact: [X]% amélioration

### Medium Effort (1-4h)
- [ ] [Action 3] - Impact: [X]% amélioration

### Major Changes (> 4h)
- [ ] [Action 4] - Impact: [X]% amélioration

## Bundle Analysis

[Tableau des plus gros packages]

## Next Steps

1. [Action prioritaire]
2. [Action suivante]

Fichier : docs/audits/PERF-{slug}-{date}.md


Output Validation

✅ Checklist Output Performance Auditor

CritèreStatus
Core Web Vitals mesurés✅/❌
Bundle size analysé✅/❌
Issues priorisées (P0/P1/P2)✅/❌
Recommandations avec impact✅/❌
Quick wins identifiés✅/❌
Budget défini✅/❌

Score minimum : 5/6


Auto-Chain

markdown
## 🔗 Prochaine étape

✅ Performance Audit terminé et sauvegardé.

→ 🔒 **Lancer `/security-auditor`** pour audit de sécurité ?
→ 💻 **Lancer `/code-implementer`** pour appliquer les optimisations ?

---

**[S] Security** | **[C] Code** | **[P] Pause**

Transitions

  • Depuis Code : "Code terminé, je fais un audit performance ?"
  • Depuis Test : "Tests OK, on vérifie les performances ?"
  • Vers Security : "Performance auditée, on passe à la sécurité ?"
  • Vers Code : "Prêt à implémenter les optimisations ?"

Exemples

Audit d'une URL

bash
/performance-auditor https://example.com

Audit du build local

bash
/performance-auditor ./dist

Focus sur le bundle

bash
/performance-auditor --bundle-only

Focus sur Lighthouse

bash
/performance-auditor --lighthouse https://example.com

Démarrage 🚀

Arguments reçus : $ARGUMENTS

Je vais maintenant :

  1. Analyser le contexte (framework, build)
  2. Mesurer les Core Web Vitals
  3. Analyser le bundle
  4. Identifier les goulots d'étranglement
  5. Proposer des optimisations priorisées

Analyse en cours...