Skip to content

feat(test): add bench mark persist#1054

Merged
ErnestM1234 merged 11 commits intomainfrom
e/bench/add-persistent-benchmark
Feb 27, 2026
Merged

feat(test): add bench mark persist#1054
ErnestM1234 merged 11 commits intomainfrom
e/bench/add-persistent-benchmark

Conversation

@ErnestM1234
Copy link
Contributor

@ErnestM1234 ErnestM1234 commented Feb 27, 2026

Motivation

The monorepo has middleware benchmarks (unit via vitest bench, E2E via Playwright) that only run locally — performance regressions can ship undetected. We need a CI system that automatically compares benchmark results against known baselines and surfaces regressions on PRs, without blocking merges while thresholds are being tuned.

Changes

  • .github/workflows/benchmark.yml — New workflow triggered on PRs (with change detection for packages/next/ and the middleware app), repository_dispatch (post-release baseline updates), and workflow_dispatch (manual trigger for external PRs). Uses github-action-benchmark with customSmallerIsBetter format, 150% alert threshold, and informational-only alerts. Baselines are stored on the gh-pages branch and only persisted on release dispatches (never on PRs, for security).
  • .github/workflows/release.yml — Added a repository_dispatch step that fires a release-published event with publishedPackages when changesets publishes, so benchmarks only run and baselines only update when gt-next is actually released.
  • tests/apps/next/middleware/benchmarks/transform-results.mjs — New script that converts vitest bench JSON and Playwright E2E performance JSON into github-action-benchmark's custom format, tagging each data point with the package name and version.
  • tests/apps/next/middleware/benchmarks/e2e-performance.spec.ts — Added BENCH_OUTPUT_NAME env var support for predictable output filenames in CI.
  • tests/apps/next/middleware/package.json — Added bench:unit:json convenience script for running vitest bench with JSON output.

Greptile Summary

Implements automated benchmark tracking for middleware performance with CI integration via GitHub Actions. The system runs unit (vitest) and E2E (Playwright) benchmarks on PRs to detect regressions, and updates baselines on releases. Key highlights:

  • Security-conscious design: Benchmark data is only persisted to gh-pages on release events, never on PRs (prevents malicious data injection from forks)
  • Smart change detection: Benchmarks only run when packages/next/ or the middleware test app changes
  • Comprehensive coverage: Tracks factory creation latency, per-request execution, TTFB, DOM load times, redirect chains, and locale switching
  • Well-integrated: Release workflow triggers benchmark baseline updates automatically when gt-next is published via repository dispatch
  • Future-ready: Includes TODO comments for generalizing the system to support multiple packages

The transform script converts vitest and Playwright outputs into github-action-benchmark format with package/version metadata. Workflow uses 150% alert threshold with informational-only alerts (non-blocking).

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Clean implementation with strong security practices (no PR data persistence), well-structured workflow logic with proper change detection, comprehensive documentation, and no critical issues found. The transform script could benefit from error handling, but this is acceptable for CI tooling.
  • No files require special attention

Important Files Changed

Filename Overview
.github/workflows/benchmark.yml New workflow for running and persisting benchmarks on PRs and releases with proper security controls
.github/workflows/release.yml Added repository dispatch to trigger benchmark baseline updates after package releases
packages/next/src/middleware-dir/tests/middleware-latency.bench.ts Moved unit benchmark file from test app to package, updated test names to include 'middleware:' prefix
scripts/transform-bench-results.mjs New script to transform vitest and Playwright benchmark outputs into github-action-benchmark format
tests/apps/next/middleware/benchmarks/e2e-performance.spec.ts Added BENCH_OUTPUT_NAME env var support and updated test result keys to include 'middleware:' prefix

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[PR/Release Event] --> B{Event Type?}
    B -->|PR| C[Check Changed Files]
    B -->|Release Dispatch| D[Check if gt-next Published]
    B -->|Manual Trigger| E[Always Run]
    
    C --> F{Should Run?}
    D --> F
    E --> F
    
    F -->|Yes| G[Setup Environment]
    F -->|No| Z[Skip]
    
    G --> H[Build Packages]
    H --> I[Run Unit Benchmarks]
    I --> J[Run E2E Benchmarks]
    J --> K[Transform Results]
    K --> L[Store & Compare with Baseline]
    
    L --> M{Event Type?}
    M -->|PR| N[Compare Only - No Persist]
    M -->|Release| O[Update Baseline on gh-pages]
    
    N --> P[Post Alert if Regression]
    O --> P
    
    style O fill:#f9f,stroke:#333
    style N fill:#bbf,stroke:#333
    style P fill:#bfb,stroke:#333
Loading

Last reviewed commit: c9d6ec8

@ErnestM1234 ErnestM1234 requested a review from a team as a code owner February 27, 2026 20:18
Base automatically changed from e/test/e2e-experimenting to main February 27, 2026 22:23
@ErnestM1234
Copy link
Contributor Author

@greptileai plz review

Copy link
Contributor

@fernando-aviles fernando-aviles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ErnestM1234 ErnestM1234 merged commit aca3c28 into main Feb 27, 2026
22 checks passed
@ErnestM1234 ErnestM1234 deleted the e/bench/add-persistent-benchmark branch February 27, 2026 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants