feat: add comprehensive performance benchmark tracking system
- Create benchmark test suites for critical operations: - Node loading performance - Database query performance - Search operations performance - Validation performance - MCP tool execution performance - Add GitHub Actions workflow for benchmark tracking: - Runs on push to main and PRs - Uses github-action-benchmark for historical tracking - Comments on PRs with performance results - Alerts on >10% performance regressions - Stores results in GitHub Pages - Create benchmark infrastructure: - Custom Vitest benchmark configuration - JSON reporter for CI results - Result formatter for github-action-benchmark - Performance threshold documentation - Add supporting utilities: - SQLiteStorageService for benchmark database setup - MCPEngine wrapper for testing MCP tools - Test factories for generating benchmark data - Enhanced NodeRepository with benchmark methods - Document benchmark system: - Comprehensive benchmark guide in docs/BENCHMARKS.md - Performance thresholds in .github/BENCHMARK_THRESHOLDS.md - README for benchmarks directory - Integration with existing test suite The benchmark system will help monitor performance over time and catch regressions before they reach production. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
86
scripts/format-benchmark-results.js
Executable file
86
scripts/format-benchmark-results.js
Executable file
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
* Formats Vitest benchmark results for github-action-benchmark
|
||||
* Converts from Vitest format to the expected format
|
||||
*/
|
||||
function formatBenchmarkResults() {
|
||||
const resultsPath = path.join(process.cwd(), 'benchmark-results.json');
|
||||
|
||||
if (!fs.existsSync(resultsPath)) {
|
||||
console.error('benchmark-results.json not found');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const vitestResults = JSON.parse(fs.readFileSync(resultsPath, 'utf8'));
|
||||
|
||||
// Convert to github-action-benchmark format
|
||||
const formattedResults = [];
|
||||
|
||||
// Vitest benchmark JSON reporter format
|
||||
if (vitestResults.files) {
|
||||
for (const file of vitestResults.files) {
|
||||
const suiteName = path.basename(file.filepath, '.bench.ts');
|
||||
|
||||
// Process each suite in the file
|
||||
if (file.groups) {
|
||||
for (const group of file.groups) {
|
||||
for (const benchmark of group.benchmarks || []) {
|
||||
if (benchmark.result) {
|
||||
formattedResults.push({
|
||||
name: `${suiteName} - ${benchmark.name}`,
|
||||
unit: 'ms',
|
||||
value: benchmark.result.mean || 0,
|
||||
range: (benchmark.result.max - benchmark.result.min) || 0,
|
||||
extra: `${benchmark.result.hz?.toFixed(0) || 0} ops/sec`
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (Array.isArray(vitestResults)) {
|
||||
// Alternative format handling
|
||||
for (const result of vitestResults) {
|
||||
if (result.name && result.result) {
|
||||
formattedResults.push({
|
||||
name: result.name,
|
||||
unit: 'ms',
|
||||
value: result.result.mean || 0,
|
||||
range: (result.result.max - result.result.min) || 0,
|
||||
extra: `${result.result.hz?.toFixed(0) || 0} ops/sec`
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write formatted results
|
||||
const outputPath = path.join(process.cwd(), 'benchmark-results-formatted.json');
|
||||
fs.writeFileSync(outputPath, JSON.stringify(formattedResults, null, 2));
|
||||
|
||||
// Also create a summary for PR comments
|
||||
const summary = {
|
||||
timestamp: new Date().toISOString(),
|
||||
benchmarks: formattedResults.map(b => ({
|
||||
name: b.name,
|
||||
time: `${b.value.toFixed(3)}ms`,
|
||||
opsPerSec: b.extra,
|
||||
range: `±${(b.range / 2).toFixed(3)}ms`
|
||||
}))
|
||||
};
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(process.cwd(), 'benchmark-summary.json'),
|
||||
JSON.stringify(summary, null, 2)
|
||||
);
|
||||
|
||||
console.log(`Formatted ${formattedResults.length} benchmark results`);
|
||||
}
|
||||
|
||||
// Run if called directly
|
||||
if (require.main === module) {
|
||||
formatBenchmarkResults();
|
||||
}
|
||||
73
scripts/vitest-benchmark-json-reporter.js
Normal file
73
scripts/vitest-benchmark-json-reporter.js
Normal file
@@ -0,0 +1,73 @@
|
||||
import { writeFileSync } from 'fs';
|
||||
import { resolve } from 'path';
|
||||
|
||||
export default class BenchmarkJsonReporter {
|
||||
constructor() {
|
||||
this.results = [];
|
||||
}
|
||||
|
||||
onTaskUpdate(tasks) {
|
||||
// Called when tasks are updated
|
||||
}
|
||||
|
||||
onFinished(files) {
|
||||
const results = {
|
||||
timestamp: new Date().toISOString(),
|
||||
files: []
|
||||
};
|
||||
|
||||
for (const file of files || []) {
|
||||
if (!file) continue;
|
||||
|
||||
const fileResult = {
|
||||
filepath: file.filepath || file.name,
|
||||
groups: []
|
||||
};
|
||||
|
||||
// Process benchmarks
|
||||
if (file.tasks) {
|
||||
for (const task of file.tasks) {
|
||||
if (task.type === 'suite' && task.tasks) {
|
||||
const group = {
|
||||
name: task.name,
|
||||
benchmarks: []
|
||||
};
|
||||
|
||||
for (const benchmark of task.tasks) {
|
||||
if (benchmark.result?.benchmark) {
|
||||
group.benchmarks.push({
|
||||
name: benchmark.name,
|
||||
result: {
|
||||
mean: benchmark.result.benchmark.mean,
|
||||
min: benchmark.result.benchmark.min,
|
||||
max: benchmark.result.benchmark.max,
|
||||
hz: benchmark.result.benchmark.hz,
|
||||
p75: benchmark.result.benchmark.p75,
|
||||
p99: benchmark.result.benchmark.p99,
|
||||
p995: benchmark.result.benchmark.p995,
|
||||
p999: benchmark.result.benchmark.p999,
|
||||
rme: benchmark.result.benchmark.rme,
|
||||
samples: benchmark.result.benchmark.samples
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (group.benchmarks.length > 0) {
|
||||
fileResult.groups.push(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fileResult.groups.length > 0) {
|
||||
results.files.push(fileResult);
|
||||
}
|
||||
}
|
||||
|
||||
// Write results
|
||||
const outputPath = resolve(process.cwd(), 'benchmark-results.json');
|
||||
writeFileSync(outputPath, JSON.stringify(results, null, 2));
|
||||
console.log(`Benchmark results written to ${outputPath}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user