npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@samithahansaka/perflock

v0.1.2

Published

Performance contracts for React components - lock in your render budgets

Readme

@samithahansaka/perflock

CI npm version License: MIT

Lock in your React component performance budgets with CI enforcement.

Table of Contents

Features

  • Define performance contracts for React components
  • Measure render times and render counts during interactions
  • Jest/Vitest matchers for assertions
  • CLI for running tests and generating reports
  • GitHub Action for CI integration with PR comments
  • Regression detection against historical baselines

Installation

npm install @samithahansaka/perflock --save-dev

Quick Start

1. Initialize Configuration

npx perflock init

This creates perf.contracts.ts:

import { defineContracts } from '@samithahansaka/perflock';

export default defineContracts({
  global: {
    runs: 10,
    regressionThreshold: 0.15,
  },
  components: {
    UserCard: {
      maxRenderTime: 16, // ms
      maxRenderCount: 3,
      interactions: {
        click: { maxRenders: 2 },
        type: { maxRenders: 1 },
      },
    },
  },
});

2. Write Performance Tests

// __perf__/UserCard.perf.tsx
import { measureInteraction, interactions } from '@samithahansaka/perflock';
import { render, fireEvent } from '@testing-library/react';
import { UserCard } from '../src/components/UserCard';

test('UserCard meets performance contract', async () => {
  const result = await measureInteraction(
    <UserCard user={mockUser} />,
    {
      interactions: [
        interactions.click('[data-testid="edit-btn"]'),
        interactions.type('[data-testid="email-input"]', '[email protected]'),
      ],
      contract: 'UserCard',
    },
    { render, fireEvent }
  );

  expect(result).toPassContract();
});

3. Run Tests

npx perflock run

API Reference

defineContracts(config)

Define performance contracts for your components.

defineContracts({
  global: {
    runs: 10, // Test runs for stability
    warmupRuns: 1, // Warmup runs to discard
    historyWindow: 20, // Compare against last N runs
    regressionThreshold: 0.15, // 15% regression threshold
  },
  components: {
    ComponentName: {
      maxRenderTime: 16, // Max average render time (ms)
      maxRenderCount: 3, // Max renders per scenario
      warningThreshold: 0.8, // Warn at 80% of budget
      interactions: {
        click: { maxRenders: 2 },
        type: { maxRenders: 1 },
      },
    },
  },
});

measureInteraction(element, options, dependencies)

Measure component renders during user interactions.

const result = await measureInteraction(
  <MyComponent />,
  {
    interactions: [
      { type: 'click', target: '[data-testid="btn"]' },
      { type: 'type', target: 'input', text: 'hello' },
    ],
    contract: 'MyComponent',
    runs: 10,
  },
  { render, fireEvent }
);

// result.metrics.renderCount
// result.metrics.averageRenderTime
// result.rendersByType.click
// result.rendersByType.type

Jest/Vitest Matchers

import { extendExpect } from '@samithahansaka/perflock/jest';

extendExpect(expect);

// Now available:
expect(result).toPassContract('ComponentName');
expect(result).toHaveRendersAtMost(5);
expect(result).toHaveRenderTimeAtMost(16);
expect(result).toHaveRendersPerInteractionAtMost('click', 2);
expect(value).toBeWithinBudget(100);

CLI Commands

# Initialize configuration
npx perflock init

# Run performance tests
npx perflock run

# Generate report
npx perflock report --format markdown

# Compare with baseline
npx perflock compare --baseline ./baseline.json

GitHub Action

name: Performance Contracts

on:
  pull_request:
    branches: [main]

jobs:
  perf-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - run: npm ci

      - uses: samithahansaka/perflock-action@v1
        with:
          test-command: 'npm run test:perf'
          fail-on-budget-exceeded: true
          comment-on-pr: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Packages

| Package | Description | | --------------------------------- | ------------- | | @samithahansaka/perflock | Core library | | @samithahansaka/perflock-cli | CLI tool | | @samithahansaka/perflock-action | GitHub Action |

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

Author

Samitha Hansaka - @samithahansaka

License

This project is licensed under the MIT License - see the LICENSE file for details.