Initial commit
This commit is contained in:
25
skills/performance-optimization/templates/INDEX.md
Normal file
25
skills/performance-optimization/templates/INDEX.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Performance Optimization Templates
|
||||
|
||||
Copy-paste templates for performance optimization reports and tests.
|
||||
|
||||
## Available Templates
|
||||
|
||||
### Optimization Report
|
||||
**File**: [optimization-report.md](optimization-report.md)
|
||||
|
||||
Template for documenting performance improvements with before/after metrics.
|
||||
|
||||
**Use when**: Completing performance optimizations, reporting to stakeholders.
|
||||
|
||||
---
|
||||
|
||||
### Performance Test
|
||||
**File**: [performance-test.js](performance-test.js)
|
||||
|
||||
Template for writing performance benchmarks.
|
||||
|
||||
**Use when**: Measuring optimization impact, regression testing.
|
||||
|
||||
---
|
||||
|
||||
Return to [main agent](../performance-optimizer.md)
|
||||
@@ -0,0 +1,66 @@
|
||||
# Performance Optimization Report
|
||||
|
||||
## Summary
|
||||
|
||||
**Date**: [YYYY-MM-DD]
|
||||
**Project**: [Project Name]
|
||||
**Optimized By**: [Your Name]
|
||||
|
||||
### Key Achievements
|
||||
- **Overall Improvement**: [X%] faster
|
||||
- **Primary Metric**: [Metric name] improved from [Before] to [After]
|
||||
- **Impact**: [Business impact, e.g., "Supports 10x more users"]
|
||||
|
||||
---
|
||||
|
||||
## Metrics Comparison
|
||||
|
||||
| Metric | Before | After | Improvement |
|
||||
|--------|--------|-------|-------------|
|
||||
| **[Metric 1]** | [Value] | [Value] | [X%/Xx faster] |
|
||||
| **[Metric 2]** | [Value] | [Value] | [X%/Xx faster] |
|
||||
| **[Metric 3]** | [Value] | [Value] | [X%/Xx faster] |
|
||||
|
||||
---
|
||||
|
||||
## Optimizations Implemented
|
||||
|
||||
### 1. [Optimization Name]
|
||||
**Problem**: [Describe the bottleneck]
|
||||
|
||||
**Solution**: [Describe the fix]
|
||||
|
||||
**Code Changes**:
|
||||
```[language]
|
||||
// Before
|
||||
[old code]
|
||||
|
||||
// After
|
||||
[new code]
|
||||
```
|
||||
|
||||
**Impact**:
|
||||
- Metric: [X%] improvement
|
||||
- Files: [[file.ts:42](file.ts#L42)]
|
||||
|
||||
---
|
||||
|
||||
### 2. [Next Optimization]
|
||||
[Same structure as above]
|
||||
|
||||
---
|
||||
|
||||
## Remaining Opportunities
|
||||
|
||||
1. **[Opportunity 1]**: [Description] - Estimated [X%] improvement
|
||||
2. **[Opportunity 2]**: [Description] - Estimated [X%] improvement
|
||||
|
||||
---
|
||||
|
||||
## Performance Budget
|
||||
|
||||
| Resource | Target | Current | Status |
|
||||
|----------|--------|---------|--------|
|
||||
| **Bundle Size** | < [X]KB | [Y]KB | ✅/❌ |
|
||||
| **LCP** | < [X]s | [Y]s | ✅/❌ |
|
||||
| **API Latency (p95)** | < [X]ms | [Y]ms | ✅/❌ |
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Performance Test Template
|
||||
*
|
||||
* Benchmark functions to measure optimization impact.
|
||||
*/
|
||||
|
||||
// Benchmark function
|
||||
function benchmark(fn, iterations = 1000) {
|
||||
const start = performance.now();
|
||||
|
||||
for (let i = 0; i < iterations; i++) {
|
||||
fn();
|
||||
}
|
||||
|
||||
const end = performance.now();
|
||||
const total = end - start;
|
||||
const avg = total / iterations;
|
||||
|
||||
return {
|
||||
total: total.toFixed(2),
|
||||
average: avg.toFixed(4),
|
||||
iterations
|
||||
};
|
||||
}
|
||||
|
||||
// Example: Before optimization
|
||||
function processItemsOld(items) {
|
||||
const result = [];
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
for (let j = 0; j < items.length; j++) {
|
||||
if (items[i].id === items[j].relatedId) {
|
||||
result.push({ item: items[i], related: items[j] });
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example: After optimization
|
||||
function processItemsNew(items) {
|
||||
const map = new Map(items.map(i => [i.id, i]));
|
||||
return items
|
||||
.filter(i => i.relatedId)
|
||||
.map(i => ({ item: i, related: map.get(i.relatedId) }));
|
||||
}
|
||||
|
||||
// Test data
|
||||
const testItems = Array.from({ length: 1000 }, (_, i) => ({
|
||||
id: i,
|
||||
relatedId: Math.floor(Math.random() * 1000)
|
||||
}));
|
||||
|
||||
// Run benchmarks
|
||||
console.log('Performance Benchmark Results\n');
|
||||
|
||||
const oldResults = benchmark(() => processItemsOld(testItems), 100);
|
||||
console.log('Before Optimization:');
|
||||
console.log(` Total: ${oldResults.total}ms`);
|
||||
console.log(` Average: ${oldResults.average}ms`);
|
||||
console.log(` Iterations: ${oldResults.iterations}\n`);
|
||||
|
||||
const newResults = benchmark(() => processItemsNew(testItems), 100);
|
||||
console.log('After Optimization:');
|
||||
console.log(` Total: ${newResults.total}ms`);
|
||||
console.log(` Average: ${newResults.average}ms`);
|
||||
console.log(` Iterations: ${newResults.iterations}\n`);
|
||||
|
||||
const improvement = ((parseFloat(oldResults.total) / parseFloat(newResults.total))).toFixed(1);
|
||||
console.log(`Performance Gain: ${improvement}x faster`);
|
||||
Reference in New Issue
Block a user