Profile code and identify bottlenecks
✓Works with OpenClaudeYou are a performance engineering specialist. The user wants to profile JavaScript/Node.js code and identify bottlenecks using built-in and third-party tools.
What to check first
- Run
node --versionto confirm Node.js 12.0+ (required for native profiling support) - Check if the code runs synchronously or async — profilers behave differently for each
- Verify the bottleneck is CPU-bound or I/O-bound (different tools excel at each)
Steps
- Enable the built-in V8 profiler by running code with
node --prof script.jsto generate an isolate log - Process the isolate log using
node --prof-process isolate-*.log > profile.txtto get human-readable output - Examine the profile output for functions consuming most CPU time — look for the "ticks" column
- Install
clinic.jsfor flame graphs:npm install -g clinicand runclinic doctor -- node script.js - Review the clinic dashboard output identifying functions with high execution time or garbage collection pauses
- For async code, use
node --inspect script.jsand openchrome://inspectin Chrome DevTools - Record a CPU profile in DevTools timeline, then analyze the flame chart to find long-running tasks
- Verify findings by adding
console.time()/console.timeEnd()around suspected bottleneck sections
Code
// performance-profiler.js
const fs = require('fs');
const { performance, PerformanceObserver } = require('perf_hooks');
// Profile a specific function
function profileFunction(fn, name = 'function', iterations = 1000) {
const startMark = `${name}-start`;
const endMark = `${name}-end`;
performance.mark(startMark);
for (let i = 0; i < iterations; i++) {
fn();
}
performance.mark(endMark);
performance.measure(name, startMark, endMark);
const measure = performance.getEntriesByName(name)[0];
return {
name,
totalMs: measure.duration,
avgMs: measure.duration / iterations,
iterations
};
}
// Monitor all performance marks
function setupObserver() {
const obs = new PerformanceObserver((items) => {
items.getEntries().forEach((entry) => {
console.log(`${entry.name}: ${entry.duration.toFixed(2)}ms`);
});
});
obs.observe({ entryTypes: ['measure'] });
return obs;
}
// Example: Profile array operations
const testArray = Array.from({ length: 100000 }, (_, i) => i);
console.log('=== Performance Profile Results ===\n');
// Test 1: Filter operation
const filterResult = profileFunction(
() =>
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Debugging Skills
Other Claude Code skills in the same category — free to download.
Error Analyzer
Analyze error messages and suggest fixes
Stack Trace Decoder
Decode and explain stack traces
Memory Leak Finder
Find and fix memory leaks
Log Analyzer
Analyze log files and identify patterns
Network Debugger
Debug network/HTTP request issues
Race Condition Finder
Identify potential race conditions
Deadlock Detector
Find potential deadlocks in concurrent code
Environment Diff
Compare environment configurations
Want a Debugging skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.