home / skills / doanchienthangdev / omgkit / performance-profiling

performance-profiling skill

/plugin/skills/devops/performance-profiling

This skill profiles browser performance using Lighthouse, Core Web Vitals, and bundle analysis to help optimize load times and budgets.

npx playbooks add skill doanchienthangdev/omgkit --skill performance-profiling

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
3.2 KB
---
name: profiling-performance
description: Performs browser performance profiling with Lighthouse, Core Web Vitals, and DevTools analysis. Use when auditing page performance, optimizing Core Web Vitals, analyzing bundle sizes, or implementing performance budgets.
category: devops
triggers:
  - performance
  - lighthouse
  - core web vitals
  - bundle size
  - profiling
---

# Profiling Performance

## Quick Start

```typescript
// Run Lighthouse audit
import lighthouse from 'lighthouse';
import * as chromeLauncher from 'chrome-launcher';

async function audit(url: string) {
  const chrome = await chromeLauncher.launch({ chromeFlags: ['--headless'] });
  const result = await lighthouse(url, { port: chrome.port, onlyCategories: ['performance'] });
  await chrome.kill();
  return result?.lhr;
}
```

```bash
# CLI audit
npx lighthouse https://example.com --output=json --output-path=./report.json
```

## Features

| Feature | Description | Guide |
|---------|-------------|-------|
| Lighthouse Audits | Automated performance scoring | Run in CI/CD, track scores over time |
| Core Web Vitals | LCP, FID, CLS, INP metrics | Monitor with web-vitals library |
| Bundle Analysis | JavaScript bundle size inspection | Use webpack-bundle-analyzer or rollup-plugin-visualizer |
| Network Waterfall | Request timing and blocking analysis | Identify render-blocking resources |
| Memory Profiling | Heap snapshots and leak detection | Compare snapshots before/after operations |
| Performance Budgets | Automated regression prevention | Set thresholds in CI pipeline |

## Common Patterns

### Core Web Vitals Monitoring

```typescript
import { onLCP, onFID, onCLS, onINP } from 'web-vitals';

function sendToAnalytics(metric: { name: string; value: number; rating: string }) {
  analytics.track('web_vital', metric);
}

onLCP(sendToAnalytics);  // Target: < 2.5s
onFID(sendToAnalytics);  // Target: < 100ms
onCLS(sendToAnalytics);  // Target: < 0.1
onINP(sendToAnalytics);  // Target: < 200ms
```

### Performance Budget Check

```typescript
const BUDGET = {
  lcp: 2500, fid: 100, cls: 0.1, tti: 3800, tbt: 200,
  jsSize: 300 * 1024, cssSize: 50 * 1024, totalSize: 1000 * 1024,
};

function checkBudget(metrics: Record<string, number>) {
  const violations = Object.entries(BUDGET)
    .filter(([key, limit]) => metrics[key] > limit)
    .map(([key, limit]) => ({ metric: key, limit, actual: metrics[key] }));
  return { passed: violations.length === 0, violations };
}
```

### CI/CD Integration

```yaml
# .github/workflows/performance.yml
- name: Lighthouse CI
  uses: treosh/lighthouse-ci-action@v10
  with:
    urls: http://localhost:3000
    budgetPath: ./performance-budget.json
    uploadArtifacts: true
```

## Best Practices

| Do | Avoid |
|----|-------|
| Test with throttled network and CPU | Testing only on fast connections |
| Monitor real user metrics (RUM) | Relying solely on synthetic tests |
| Set and enforce performance budgets | Optimizing without baseline data |
| Preload LCP images with fetchpriority | Ignoring mobile performance |
| Lazy load below-fold content | Loading all JS upfront |
| Use modern image formats (WebP, AVIF) | Ignoring third-party script impact |
| Profile before and after changes | Skipping cumulative layout shift fixes |

Overview

This skill performs browser performance profiling using Lighthouse, Core Web Vitals, and DevTools techniques to pinpoint real-world and synthetic bottlenecks. It combines automated audits, RUM metric collection, bundle inspection, and memory profiling to create actionable optimization guidance. Use it to enforce performance budgets, track regressions in CI, and prioritize fixes that impact user experience.

How this skill works

The skill runs Lighthouse audits (locally or in CI) to produce performance scores and trace data, and captures Core Web Vitals via the web-vitals API for real user monitoring. It inspects bundle sizes with analyzers, generates network waterfalls and DevTools traces, and compares heap snapshots to find memory leaks. Performance budgets are checked programmatically and can fail CI when thresholds are exceeded.

When to use it

  • Auditing a page for performance regressions before a release
  • Setting up real user monitoring for Core Web Vitals (LCP, FID/INP, CLS)
  • Analyzing bundle size and unused JavaScript/CSS
  • Creating automated performance checks in CI/CD pipelines
  • Investigating memory growth or leaks in client code

Best practices

  • Run audits on throttled network and CPU to simulate realistic conditions
  • Collect RUM metrics in production alongside synthetic tests
  • Establish and enforce measurable performance budgets in CI
  • Preload critical LCP images and use fetchpriority where appropriate
  • Lazy-load below-the-fold content and third-party scripts
  • Profile before and after changes to verify impact

Example use cases

  • Automate Lighthouse audits in a GitHub Actions workflow and fail when budgets are breached
  • Send LCP, FID/INP, and CLS events from the web-vitals library to analytics for trend analysis
  • Use webpack-bundle-analyzer to locate and split large vendor chunks and reduce initial JS payload
  • Record DevTools network waterfalls to identify render-blocking resources and improve critical request chains
  • Capture heap snapshots before/after a feature to identify memory leaks introduced by event listeners

FAQ

Can this detect real user experiences as well as lab metrics?

Yes. Use Lighthouse for lab-based traces and the web-vitals library to capture real user metrics (RUM) for LCP, FID/INP, and CLS.

How do I enforce performance budgets in CI?

Define numeric thresholds (LCP, TBT, JS size, etc.), run Lighthouse or budget checks in your CI workflow, and fail the job when violations are reported.