Skip to content

Introduction

react-performance-tracking automates React render performance checks in Playwright. Capture React Profiler metrics, apply CPU throttling, run warmups, enforce budgets, and catch performance regressions before they hit production.

Why Use This?

  • Catch performance regressions early – Detect slow renders before they reach production
  • Real-world conditions – Test with CPU throttling, network throttling, and device simulation
  • CI/CD integration – Fail builds automatically when performance budgets are exceeded
  • Comprehensive metrics – Track React renders, FPS, memory usage, and Core Web Vitals
  • Zero boilerplate – Drop-in Playwright integration with minimal configuration

Features

FeatureDescriptionBrowser Support
📊 React ProfilerCollect real render metrics via React's Profiler APIAll
🎭 Playwright Integrationtest.performance() helper and performance fixtureAll
🧩 Component ProfilingTrack per-component metrics with multiple profilersAll
🎞️ FPS TrackingMeasure average FPS via Chrome DevTools ProtocolChromium
🧠 Memory TrackingTrack heap growth to detect memory leaksChromium
📈 Web VitalsCapture LCP, INP, CLS via PerformanceObserverAll
🐢 CPU ThrottlingSimulate slower devicesChromium
🌐 Network ThrottlingSimulate slow networks (3G/4G presets)Chromium
⏱️ Custom MetricsTrack custom performance marks and measuresAll
🔥 Warmup RunsReduce cold-start noise (default on CI)All
🔄 Multiple IterationsRun tests multiple times with percentile metricsAll
📊 Trace ExportExport Chrome DevTools traces for flamegraphChromium

How It Works

The library has a two-layer architecture:

React Layer (Browser)

Wrap your app with PerformanceProvider and use <Profiler> components to collect render metrics. The provider exposes a window.__REACT_PERFORMANCE__ store that aggregates metrics globally and per-component.

Playwright Layer (Node.js)

Use createPerformanceTest() to extend Playwright with test.performance(). The test runner orchestrates: setup → warmup → test → assertions → cleanup. It communicates with the browser via page.evaluate() to retrieve metrics.

┌─────────────────────────────────────────────────────┐
│  Playwright Test (Node.js)                          │
│  ┌──────────────────────────────────────────────┐   │
│  │  test.performance({ thresholds: {...} })     │   │
│  │  ├─ Setup (throttling, features)             │   │
│  │  ├─ Warmup iteration (if enabled)            │   │
│  │  ├─ Test iterations                          │   │
│  │  ├─ Assertions (thresholds + buffers)        │   │
│  │  └─ Cleanup (CDP sessions)                   │   │
│  └──────────────────────────────────────────────┘   │
│                      │                              │
│                      │ page.evaluate()              │
│                      ▼                              │
│  ┌──────────────────────────────────────────────┐   │
│  │  Browser (window.__REACT_PERFORMANCE__)      │   │
│  │  ├─ samples: PerformanceSample[]             │   │
│  │  ├─ components: { [id]: ComponentMetrics }   │   │
│  │  └─ reset: () => void                        │   │
│  └──────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────┘

Requirements

  • React 18+ or 19+
  • Playwright 1.40+
  • Node.js 18+

Next Steps

Ready to get started? Follow these guides:

  1. Installation – Install the package
  2. Quick Start – Write your first performance test
  3. React Setup – Configure your React app
  4. Playwright Setup – Set up Playwright integration