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:
czlonkowski
2025-07-28 22:45:09 +02:00
parent 0252788dd6
commit b5210e5963
52 changed files with 6843 additions and 16 deletions

56
.github/BENCHMARK_THRESHOLDS.md vendored Normal file
View File

@@ -0,0 +1,56 @@
# Performance Benchmark Thresholds
This file defines the expected performance thresholds for n8n-mcp operations.
## Critical Operations
| Operation | Expected Time | Warning Threshold | Error Threshold |
|-----------|---------------|-------------------|-----------------|
| Node Loading (per package) | <100ms | 150ms | 200ms |
| Database Query (simple) | <5ms | 10ms | 20ms |
| Search (simple word) | <10ms | 20ms | 50ms |
| Search (complex query) | <50ms | 100ms | 200ms |
| Validation (simple config) | <1ms | 2ms | 5ms |
| Validation (complex config) | <10ms | 20ms | 50ms |
| MCP Tool Execution | <50ms | 100ms | 200ms |
## Benchmark Categories
### Node Loading Performance
- **loadPackage**: Should handle large packages efficiently
- **loadNodesFromPath**: Individual file loading should be fast
- **parsePackageJson**: JSON parsing overhead should be minimal
### Database Query Performance
- **getNodeByType**: Direct lookups should be instant
- **searchNodes**: Full-text search should scale well
- **getAllNodes**: Pagination should prevent performance issues
### Search Operations
- **OR mode**: Should handle multiple terms efficiently
- **AND mode**: More restrictive but still performant
- **FUZZY mode**: Slower but acceptable for typo tolerance
### Validation Performance
- **minimal profile**: Fastest, only required fields
- **ai-friendly profile**: Balanced performance
- **strict profile**: Comprehensive but slower
### MCP Tool Execution
- Tools should respond quickly for interactive use
- Complex operations may take longer but should remain responsive
## Regression Detection
Performance regressions are detected when:
1. Any operation exceeds its warning threshold by 10%
2. Multiple operations show degradation in the same category
3. Average performance across all benchmarks degrades by 5%
## Optimization Targets
Future optimization efforts should focus on:
1. **Search performance**: Implement FTS5 for better full-text search
2. **Caching**: Add intelligent caching for frequently accessed nodes
3. **Lazy loading**: Defer loading of large property schemas
4. **Batch operations**: Optimize bulk inserts and updates

17
.github/gh-pages.yml vendored Normal file
View File

@@ -0,0 +1,17 @@
# GitHub Pages configuration for benchmark results
# This file configures the gh-pages branch to serve benchmark results
# Path to the benchmark data
benchmarks:
data_dir: benchmarks
# Theme configuration
theme:
name: minimal
# Navigation
nav:
- title: "Performance Benchmarks"
url: /benchmarks/
- title: "Back to Repository"
url: https://github.com/czlonkowski/n8n-mcp

146
.github/workflows/benchmark.yml vendored Normal file
View File

@@ -0,0 +1,146 @@
name: Performance Benchmarks
on:
push:
branches: [main, feat/comprehensive-testing-suite]
pull_request:
branches: [main]
workflow_dispatch:
permissions:
# For PR comments
pull-requests: write
# For pushing to gh-pages branch
contents: write
# For deployment to GitHub Pages
pages: write
id-token: write
jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Fetch all history for proper benchmark comparison
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build
- name: Run benchmarks
run: npm run benchmark:ci
- name: Format benchmark results
run: node scripts/format-benchmark-results.js
- name: Upload benchmark artifacts
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: |
benchmark-results.json
benchmark-results-formatted.json
benchmark-summary.json
# Store benchmark results and compare
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
name: n8n-mcp Benchmarks
tool: 'customSmallerIsBetter'
output-file-path: benchmark-results-formatted.json
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
# Where to store benchmark data
benchmark-data-dir-path: 'benchmarks'
# Alert when performance regresses by 10%
alert-threshold: '110%'
# Comment on PR when regression is detected
comment-on-alert: true
alert-comment-cc-users: '@czlonkowski'
# Summary always
summary-always: true
# Max number of data points to retain
max-items-in-chart: 50
# Comment on PR with benchmark results
- name: Comment PR with results
uses: actions/github-script@v7
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const summary = JSON.parse(fs.readFileSync('benchmark-summary.json', 'utf8'));
// Format results for PR comment
let comment = '## 📊 Performance Benchmark Results\n\n';
comment += `🕐 Run at: ${new Date(summary.timestamp).toLocaleString()}\n\n`;
comment += '| Benchmark | Time | Ops/sec | Range |\n';
comment += '|-----------|------|---------|-------|\n';
// Group benchmarks by category
const categories = {};
for (const benchmark of summary.benchmarks) {
const [category, ...nameParts] = benchmark.name.split(' - ');
if (!categories[category]) categories[category] = [];
categories[category].push({
...benchmark,
shortName: nameParts.join(' - ')
});
}
// Display by category
for (const [category, benchmarks] of Object.entries(categories)) {
comment += `\n### ${category}\n`;
for (const benchmark of benchmarks) {
comment += `| ${benchmark.shortName} | ${benchmark.time} | ${benchmark.opsPerSec} | ${benchmark.range} |\n`;
}
}
// Add comparison link
comment += '\n\n📈 [View historical benchmark trends](https://czlonkowski.github.io/n8n-mcp/benchmarks/)\n';
comment += '\n⚡ Performance regressions >10% will be flagged automatically.\n';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
# Deploy benchmark results to GitHub Pages
deploy:
needs: benchmark
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: gh-pages
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: '.'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

View File

@@ -15,6 +15,20 @@ jobs:
node-version: 20
cache: 'npm'
- run: npm ci
- run: npm test # Now runs Vitest with all 68 tests passing
- run: npm run test:coverage # Run tests with coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/lcov.info
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
verbose: true
- run: npm run lint
- run: npm run typecheck || true # Allow to fail initially
- run: npm run typecheck || true # Allow to fail initially
# Run benchmarks as part of CI (without performance regression checks)
- name: Run benchmarks (smoke test)
run: npm run benchmark -- --run tests/benchmarks/sample.bench.ts
continue-on-error: true