| name | edge-performance-optimizer |
| description | Automatically optimizes Cloudflare Workers performance during development, focusing on cold starts, bundle size, edge caching, and global latency |
| triggers | ["bundle size changes","fetch calls","storage operations","dependency additions","sequential operations"] |
Edge Performance Optimizer SKILL
Activation Patterns
This SKILL automatically activates when:
- New dependencies are added to package.json
- Large files or heavy imports are detected
- Sequential operations that could be parallelized
- Missing edge caching opportunities
- Bundle size increases significantly
- Storage operations without optimization patterns
Expertise Provided
Edge-Specific Performance Optimization
- Cold Start Optimization: Minimizes bundle size and heavy dependencies
- Global Distribution: Ensures edge caching for global performance
- CPU Time Optimization: Identifies CPU-intensive operations
- Storage Performance: Optimizes KV/R2/D1 access patterns
- Parallel Operations: Suggests parallelization opportunities
- Bundle Analysis: Monitors and optimizes bundle size
Specific Checks Performed
❌ Performance Anti-Patterns
import axios from 'axios';
import moment from 'moment';
import _ from 'lodash';
const user = await env.USERS.get(id);
const settings = await env.SETTINGS.get(id);
const prefs = await env.PREFS.get(id);
✅ Performance Best Practices
const response = await fetch(url);
const now = new Date();
const [user, settings, prefs] = await Promise.all([
env.USERS.get(id),
env.SETTINGS.get(id),
env.PREFS.get(id),
]);
Integration Points
Complementary to Existing Components
- edge-performance-oracle agent: Handles comprehensive performance analysis, SKILL provides immediate optimization
- workers-runtime-validator SKILL: Complements runtime checks with performance optimization
- es-deploy command: SKILL ensures performance standards before deployment
Escalation Triggers
- Complex performance architecture questions →
edge-performance-oracle agent
- Global distribution strategy →
cloudflare-architecture-strategist agent
- Performance troubleshooting →
edge-performance-oracle agent
Validation Rules
P1 - Critical (Performance Killer)
- Large Dependencies: Heavy libraries like moment, lodash, axios
- Bundle Size: Over 200KB (kills cold start performance)
- Sequential Operations: Multiple sequential storage/network calls
- Missing Edge Caching: No caching for frequently accessed data
P2 - High (Performance Impact)
- Bundle Size: Over 100KB (slows cold starts)
- CPU Time: Operations approaching 50ms limit
- Lazy Loading: Dynamic imports that hurt cold start
- Large Payloads: Responses over 100KB without streaming
P3 - Medium (Optimization Opportunity)
- Bundle Size: Over 50KB (could be optimized)
- Missing Parallelization: Operations that could be parallel
- No Request Caching: Repeated expensive operations
Remediation Examples
Fixing Heavy Dependencies
import axios from 'axios';
import moment from 'moment';
import _ from 'lodash';
const response = await fetch(url);
const data = await response.json();
const now = new Date();
const tomorrow = new Date(Date.now() + 86400000);
const unique = [...new Set(array)];
const grouped = array.reduce((acc, item) => {
const key = item.category;
if (!acc[key]) acc[key] = [];
acc[key].push(item);
return acc;
}, {});
Fixing Sequential Operations
export default {
async fetch(request: Request, env: Env) {
const user = await env.USERS.get(userId);
const settings = await env.SETTINGS.get(id);
const prefs = await env.PREFS.get(id);
}
}
export default {
async fetch(request: Request, env: Env) {
const [user, settings, prefs] = await Promise.all([
env.USERS.get(userId),
env.SETTINGS.get(id),
env.PREFS.get(id),
]);
}
}
Fixing Missing Edge Caching
export default {
async fetch(request: Request, env: Env) {
const config = await fetch('https://api.example.com/config');
}
}
export default {
async fetch(request: Request, env: Env) {
const cache = caches.default;
const cacheKey = new Request('https://example.com/config', {
method: 'GET'
});
let response = await cache.match(cacheKey);
if (!response) {
response = await fetch('https://api.example.com/config');
response = new Response(response.body, {
...response,
headers: {
...response.headers,
'Cache-Control': 'public, max-age=3600',
}
});
await cache.put(cacheKey, response.clone());
}
return response;
}
}
Fixing CPU Time Issues
export default {
async fetch(request: Request, env: Env) {
const users = await env.DB.prepare('SELECT * FROM users').all();
const enriched = users.results.map(user => {
return {
...user,
fullName: `${user.firstName} ${user.lastName}`,
};
});
}
}
export default {
async fetch(request: Request, env: Env) {
const users = await env.DB.prepare(
'SELECT * FROM users LIMIT ? OFFSET ?'
).bind(10, offset).all();
const { readable, writable } = new TransformStream();
const id = env.PROCESSOR.newUniqueId();
const stub = env.PROCESSOR.get(id);
return stub.fetch(request);
}
}
MCP Server Integration
When Cloudflare MCP server is available:
- Query real performance metrics (cold start times, CPU usage)
- Analyze global latency by region
- Get latest performance optimization techniques
- Check bundle size impact on cold starts
Benefits
Immediate Impact
- Faster Cold Starts: Reduces bundle size and heavy dependencies
- Better Global Performance: Ensures edge caching for worldwide users
- Lower CPU Usage: Identifies and optimizes CPU-intensive operations
- Reduced Latency: Parallelizes operations and adds caching
Long-term Value
- Consistent Performance Standards: Ensures all code meets performance targets
- Better User Experience: Faster response times globally
- Cost Optimization: Reduced CPU time usage lowers costs
Usage Examples
During Dependency Addition
During Storage Operations
During API Development
Performance Targets
Bundle Size
- Excellent: < 10KB
- Good: < 50KB
- Acceptable: < 100KB
- Needs Improvement: > 100KB
- Action Required: > 200KB
Cold Start Time
- Excellent: < 3ms
- Good: < 5ms
- Acceptable: < 10ms
- Needs Improvement: > 10ms
- Action Required: > 20ms
Global Latency (P95)
- Excellent: < 100ms
- Good: < 200ms
- Acceptable: < 500ms
- Needs Improvement: > 500ms
- Action Required: > 1000ms
This SKILL ensures Workers performance by providing immediate, autonomous optimization of performance patterns, preventing common performance issues and ensuring fast global response times.