Skip to content

amiyaDev/react-perf-guard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

22 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

โšก react-perf-guard

Performance Guard for React Applications

Catch performance issues before they reach production

npm version License: MIT PRs Welcome

Quick Start โ€ข Features โ€ข Documentation โ€ข Examples


๐ŸŽฏ What is react-perf-guard?

react-perf-guard (Performance Guard) is a development-first performance guardrail for React applications that continuously monitors component rendering during development and automatically detects performance issues, regressions, and UX risks โ€” before they ever reach production.

It's a dev-only runtime performance analysis tool that works silently in the background, applying a rule-based analysis engine to surface clear, actionable signals instead of noisy metrics.

Think of it as ESLint for runtime performance โ€” continuous, automatic, and built for developers.


๐Ÿค” Why react-perf-guard?

โŒ The Problem Today

  • React DevTools Profiler requires manual intervention
  • Lighthouse runs after performance degradation occurs
  • Performance regressions slip through silently
  • Console logs create noise and alert fatigue
  • Teams lack continuous performance feedback
  • Performance audits happen too late in the cycle

โœ… The react-perf-guard Solution

  • Automatic render performance detection
  • Continuous monitoring during development
  • Intelligent rule-based insights
  • Deduplicated issue reporting
  • Trend & regression detection
  • Real-time performance feedback

How It's Different

Traditional Approach react-perf-guard
Manual profiling sessions โœจ Automatic detection
One-time snapshots ๐Ÿ“Š Continuous monitoring
Raw timing numbers ๐ŸŽฏ Rule-based insights
Console spam ๐Ÿ”• Deduplicated issues
No historical data ๐Ÿ“ˆ Trend & regression analysis
Post-development audits ๐Ÿš€ Development-time prevention

Make performance a continuous development signal โ€” not a last-minute crisis.


โœจ Key Features

๐Ÿš€ Automatic Detection

Monitors component renders without manual profiling sessions

๐Ÿ“‰ Regression Analysis

Detects performance degradation through trend analysis

๐Ÿง  Smart Rule Engine

Confidence-based system prevents false positives

๐ŸŽฏ Context-Aware

Boundary-aware severity tuning for accurate reporting

๐Ÿ”• Noise-Resistant

Suppresses one-off spikes and repetitive warnings

๐Ÿ–ฅ๏ธ Built-in Panel

Visual dashboard for tracking issues in real-time

๐Ÿ”’ Production-Safe

Automatically disabled in production builds

โšก Worker-Based

Analysis runs off-thread for zero impact

๐ŸŽจ Framework-Friendly

Works with Next.js, Create React App, Vite


๐Ÿ—๏ธ How react-perf-guard Works

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  React Profiler     โ”‚  โ† Captures component render metrics
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ”‚
           โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Metrics Collector   โ”‚  โ† Batches data in-memory
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ”‚
           โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Batch Flush       โ”‚  โ† Sends metrics at intervals
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ”‚
           โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Analyzer Web Worker โ”‚  โšก Runs off the main thread
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ”‚
           โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Rule Engine       โ”‚  โ† Evaluates performance patterns
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ”‚
           โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Issue Aggregation   โ”‚  โ† Deduplicates & prioritizes
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ”‚
           โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
           โ–ผ              โ–ผ              
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚  Panel  โ”‚   โ”‚  Alerts  โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Architecture Overview:

  1. React Profiler captures render metrics from instrumented components
  2. Metrics Collector batches data in-memory for efficiency
  3. Batch Flush sends accumulated metrics at intervals
  4. Analyzer Web Worker processes data off the main thread
  5. Rule Engine evaluates performance patterns against rules
  6. Issue Aggregation deduplicates and prioritizes findings
  7. PerfGuard Panel displays actionable insights to developers

All heavy analysis runs in a Web Worker, keeping your application fast and responsive.


๐Ÿ“ฆ Installation

# Using npm
npm install react-perf-guard

# Using pnpm
pnpm add react-perf-guard

# Using yarn
yarn add react-perf-guard

Requirements:

  • React 16.8+ (Hooks support)
  • Development environment (automatically disabled in production)

๐Ÿš€ Quick Start

1๏ธโƒฃ Wrap Your App with PerfProvider

The PerfProvider is the entry point that initializes the performance monitoring system.

import { PerfProvider } from "react-perf-guard";

export function App() {
  return (
    <PerfProvider>
      <YourApp />
    </PerfProvider>
  );
}

What happens under the hood:

  • โœ… Starts the analyzer worker thread
  • โœ… Loads performance rules into the engine
  • โœ… Begins automatic metric flushing
  • โœ… Mounts the PerfGuard Panel UI

๐Ÿ”’ Production Safety: react-perf-guard automatically disables itself in production with zero overhead.


2๏ธโƒฃ Instrument Components (optional but recommended)

Choose the approach that fits your code style. Both methods use React's built-in Profiler API internally.

๐ŸŽจ Option A โ€” withPerfGuard HOC (Higher-Order Component)

Perfect for wrapping existing components without modifying their structure.

import { withPerfGuard } from "react-perf-guard";

function HeavyComponent() {
  return <div>Heavy UI rendering logic</div>;
}

// Wrap and export
export default withPerfGuard(HeavyComponent);

๐ŸŽจ Option B โ€” PerfProfiler Component Wrapper

Great for explicit profiling or conditional instrumentation.

import { PerfProfiler } from "react-perf-guard";

export function ProductPage() {
  return (
    <PerfProfiler id="ProductList">
      <ProductList />
    </PerfProfiler>
  );
}

Best Practices:

  • Instrument components at route/page boundaries
  • Profile known performance-sensitive components
  • Use descriptive IDs for easier debugging

๐Ÿ–ฅ๏ธ PerfGuard Panel

The PerfGuard Panel is your performance command center โ€” a visual dashboard that appears automatically in development.

๐Ÿ“Š What It Shows

  • Active Issues: Current performance problems
  • Resolved Issues: Previously fixed problems
  • Severity Levels: LOW โ†’ MEDIUM โ†’ HIGH โ†’ CRITICAL
  • Confidence Scores: Trend-based reliability indicator
  • Component Names: Exact location of issues
  • Rule IDs: Which performance rule was triggered
  • Expandable Details: Full context and recommendations

๐ŸŽฏ Panel Features

  • Real-time Updates: Issues appear as they're detected
  • Issue Filtering: Focus on specific severity levels
  • Historical View: Track resolution over time
  • One-Click Details: Expand for full diagnostic info
  • Minimal UI: Unobtrusive during development
  • Auto-hidden: Never appears in production

The panel is your single source of truth for React performance issues during development.


๐Ÿšจ Critical Alerts

When critical performance issues are detected, react-perf-guard escalates visibility to ensure you don't miss user-impacting problems.

What Makes an Issue "Critical"?

Critical issues indicate likely user-visible UX problems such as:

  • Render times exceeding 100ms (blocking the main thread)
  • Repeated severe performance degradation
  • High-confidence regression detection

Critical Alert Behavior

  • ๐Ÿ”ด Visually Highlighted: Red indicators in the panel
  • ๐Ÿ“ข Reported Once: Per component lifecycle to avoid spam
  • ๐Ÿ“Œ Persistent Display: Remains visible until resolved
  • ๐ŸŽฏ High Priority: Sorted to the top of the issue list

This prevents alert fatigue while ensuring serious regressions get immediate attention.


๐ŸŽฏ Boundary Types

Boundary types provide context-aware severity tuning โ€” the same render time means different things for different component types.

Boundary Type Description Example Use Cases Severity Adjustment
INLINE Small child component Buttons, icons, labels Softened (higher threshold)
ROUTE Page or route boundary Full page components Standard severity
LAYOUT Layout or shell component Navigation, sidebars, wrappers Moderate severity

Why This Matters

A 50ms render might be:

  • โœ… Acceptable for a route-level page component
  • โš ๏ธ Concerning for a layout shell
  • ๐Ÿšจ Critical for an inline button

Boundary types ensure you get accurate, actionable signals instead of false alarms.


๐Ÿง  Rule Engine Overview

The rule engine is the brain of react-perf-guard, transforming raw metrics into actionable performance insights.

How Rules Work

Current Render Snapshot + Historical Data
              โ†“
    Declarative Rule Evaluation
              โ†“
    Pattern & Trend Detection
              โ†“
  Confidence Score Calculation
              โ†“
    Issue Classification

Key Characteristics

  • ๐Ÿ“‹ Declarative Rules: Define what to look for, not how to find it
  • ๐Ÿ“Š Historical Context: Evaluates current performance against past trends
  • ๐ŸŽš๏ธ Confidence-Based: Scores increase only when issues persist
  • ๐Ÿ›ก๏ธ False Positive Prevention: Ignores one-off spikes and anomalies
  • ๐Ÿ”„ Adaptive: Learns normal patterns for each component

Perfect for long development sessions and real feature work, not just contrived demos.


๐Ÿ”’ Production Safety Guarantee

react-perf-guard is designed with production safety as the top priority.

What Gets Disabled in Production

// Development: Full monitoring enabled
if (process.env.NODE_ENV === 'development') {
  // โœ… React Profiler active
  // โœ… Web Worker running
  // โœ… Rule engine processing
  // โœ… Dev Panel visible
  // โœ… Metrics collection active
}

// Production: Everything disabled
if (process.env.NODE_ENV === 'production') {
  // โŒ No React Profiler
  // โŒ No Web Worker
  // โŒ No Dev Panel
  // โŒ No memory overhead
  // โŒ No runtime cost
}

Zero Production Footprint

  • No bundle size impact (tree-shaken away)
  • No memory allocation for metrics
  • No CPU cycles for analysis
  • No network requests for reporting
  • No visual components rendered

Safe by default. Zero cost in production. Guaranteed.


โšก Framework Integration

Using with Next.js

react-perf-guard works seamlessly with both Next.js routing paradigms.

๐Ÿ“„ Pages Router

Wrap your application in _app.tsx:

import type { AppProps } from "next/app";
import { PerfProvider } from "react-perf-guard";

export default function MyApp({ Component, pageProps }: AppProps) {
  return (
    <PerfProvider>
      <Component {...pageProps} />
    </PerfProvider>
  );
}

๐Ÿ—‚๏ธ App Router

Create a client-side provider component:

// app/providers.tsx
"use client";

import { PerfProvider } from "react-perf-guard";
import { ReactNode } from "react";

export function Providers({ children }: { children: ReactNode }) {
  return <PerfProvider>{children}</PerfProvider>;
}

Then use it in your root layout:

// app/layout.tsx
import { Providers } from "./providers";

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <Providers>{children}</Providers>
      </body>
    </html>
  );
}

Other Frameworks

  • Create React App: Wrap in src/index.tsx
  • Vite: Wrap in src/main.tsx
  • Remix: Wrap in app/root.tsx

๐Ÿ›ฃ๏ธ Roadmap

We're actively developing features to make react-perf-guard even more powerful:

๐Ÿ”œ Coming Soon

  • Custom Rule Authoring API
    Define your own performance rules and thresholds

  • CI/CD Integration
    GitHub Actions support for automated performance checks

  • Performance Budgets
    Set and enforce render time budgets per component

๐Ÿ”ฎ Future Vision

  • Exportable Reports
    Generate performance reports for documentation

  • Ignore Annotations
    Suppress specific warnings when intentional

  • Dashboard Integrations
    Connect to monitoring platforms

Want to contribute? We welcome PRs and feature suggestions!


๐Ÿ“š Additional Resources


๐Ÿค Contributing

We welcome contributions! Whether it's:

  • ๐Ÿ› Bug reports
  • ๐Ÿ’ก Feature suggestions
  • ๐Ÿ“– Documentation improvements
  • ๐Ÿ”ง Code contributions

Please check our contributing guidelines before submitting a PR.


๐Ÿ“„ License

MIT ยฉ Amiya Das


โญ Final Word

Performance should fail early, clearly, and with context.

react-perf-guard transforms performance from a last-minute fire drill into a daily development habit.

Stop shipping performance regressions. Start building faster React apps.

Ready to guard your React performance?

npm install react-perf-guard

Get Started โ€ข View Examples โ€ข Read Docs


Made with โšก for React developers who care about performance

Star this repo if you find it useful! โญ

About

Performance Guard for React Applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published