Skip to content

Merge pull request #539 from observerr411/main #287

Merge pull request #539 from observerr411/main

Merge pull request #539 from observerr411/main #287

Workflow file for this run

name: Benchmarks
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
benchmark:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- name: Install dependencies
run: npm ci --legacy-peer-deps
- name: Run benchmarks
id: bench
run: npm run bench -- --reporter=verbose 2>&1 | tee bench-results.txt
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmark-results-node${{ matrix.node-version }}
path: bench-results.txt
- name: Check for regressions
run: |
# Flag if any benchmark shows >10% slower than baseline
# Baseline thresholds (ops/sec):
# result construction: > 1,000,000 ops/sec
# validateTransaction: > 100,000 ops/sec
# formatAddress: > 1,000,000 ops/sec
#
# Currently: report results only. Regression gating can be enabled
# once stable baselines are committed to the repo.
echo "Benchmark results for Node.js ${{ matrix.node-version }}:"
cat bench-results.txt
- name: Post benchmark results as PR comment
if: github.event_name == 'pull_request' && matrix.node-version == '20.x'
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const results = fs.readFileSync('bench-results.txt', 'utf8');
const body = [
'## Benchmark Results (Node 20)',
'',
'```',
results.slice(0, 5000),
'```',
'',
'_Benchmarks run on Node.js 20.x. Acceptable regression threshold: 10% slower than baseline._',
].join('\n');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c =>
c.user.login === 'github-actions[bot]' &&
c.body.startsWith('## Benchmark Results')
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}