From harness-claude
Profiles Node.js apps using --prof, clinic.js, heap snapshots, perf_hooks, and event loop monitoring. Diagnoses slow endpoints, memory leaks, high CPU, and lag.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Profile Node.js applications using --prof, clinic.js, memory snapshots, and event loop lag
Profiles apps to identify CPU/memory bottlenecks using runtime tools: clinic.js/0x for Node.js, py-spy/cProfile for Python, Chrome DevTools/Lighthouse for frontend. For slow apps, leaks, high CPU.
Profiles application performance, identifies bottlenecks, and optimizes hot paths using CPU profiling, flame graphs, and benchmarking. Use when investigating performance issues or optimizing critical code paths.
Profiles Node.js code with perf_hooks, V8 inspector, heap snapshots; runs Lighthouse web audits; uses Gemini AI for optimization analysis. For hotspots, benchmarks, memory issues.
Share bugs, ideas, or general feedback.
Profile Node.js applications using --prof, clinic.js, memory snapshots, and event loop lag
--prof:node --prof app.js
# Generate human-readable output
node --prof-process isolate-*.log > profile.txt
node --inspect app.js
# Open chrome://inspect in Chrome
# Click "inspect" on the Node.js target
# Use the Performance and Memory tabs
import { monitorEventLoopDelay } from 'node:perf_hooks';
const histogram = monitorEventLoopDelay({ resolution: 20 });
histogram.enable();
setInterval(() => {
console.log({
min: histogram.min / 1e6, // ms
max: histogram.max / 1e6,
mean: histogram.mean / 1e6,
p99: histogram.percentile(99) / 1e6,
});
histogram.reset();
}, 5000);
import { performance, PerformanceObserver } from 'node:perf_hooks';
performance.mark('start');
await processData();
performance.mark('end');
performance.measure('processData', 'start', 'end');
const entries = performance.getEntriesByName('processData');
console.log(`Duration: ${entries[0].duration}ms`);
function logMemory() {
const { heapUsed, heapTotal, external, rss } = process.memoryUsage();
console.log({
heapUsed: `${(heapUsed / 1024 / 1024).toFixed(1)} MB`,
heapTotal: `${(heapTotal / 1024 / 1024).toFixed(1)} MB`,
rss: `${(rss / 1024 / 1024).toFixed(1)} MB`,
});
}
setInterval(logMemory, 10_000);
import v8 from 'node:v8';
import { writeFileSync } from 'node:fs';
function takeHeapSnapshot() {
const filename = `heap-${Date.now()}.heapsnapshot`;
const snapshotStream = v8.writeHeapSnapshot(filename);
console.log(`Heap snapshot written to ${snapshotStream}`);
}
// Take snapshots at intervals to compare in Chrome DevTools
npx clinic doctor -- node app.js
# Generates a flamechart visualization
npx clinic flame -- node app.js
# Generates a flamegraph for CPU profiling
npx clinic bubbleprof -- node app.js
# Visualizes async operations
// Cache expensive computations
const cache = new Map<string, Result>();
async function getCachedResult(key: string): Promise<Result> {
if (cache.has(key)) return cache.get(key)!;
const result = await expensiveComputation(key);
cache.set(key, result);
return result;
}
// Use setImmediate to yield the event loop during CPU work
async function processLargeArray(items: Item[]) {
for (let i = 0; i < items.length; i++) {
processItem(items[i]);
if (i % 1000 === 0) {
await new Promise((resolve) => setImmediate(resolve));
}
}
}
Node.js performance profiling identifies CPU bottlenecks, memory leaks, and event loop blocking that cause high latency or resource exhaustion.
Key metrics:
Flamegraphs: Visual representations of CPU time across call stacks. Wide bars indicate functions consuming significant CPU. Available through Chrome DevTools Performance tab or clinic flame.
Memory leak patterns:
setInterval without clearInterval)Trade-offs:
--prof is built-in — but produces hard-to-read output without processingclinic.js automates analysis — but is a development-only toolhttps://nodejs.org/en/docs/guides/simple-profiling