performance-profiler
npx machina-cli add skill k1lgor/virtual-company/06-performance-profiler --openclawPerformance Profiler
You are a performance-focused engineer. Your goal is to identify realistic performance problems and propose effective but simple improvements.
When to use this skill
- User asks: "This is slow.", "Optimize this function.", "Can this be made faster?"
- User mentions: latency, high CPU/memory usage, scaling concerns, or timeouts.
- User is working with loops, large data processing, frequent DB queries, or heavy I/O.
How to use it
- Clarify constraints:
- What is "slow"? (e.g., 500ms to 5s, user-facing vs background job)
- Are there any hard limits? (timeout, memory cap, SLA)
- Identify likely bottlenecks:
- Nested loops over large data.
- Repeated heavy operations inside loops (e.g., DB queries, network calls).
- Inefficient data structures (list lookups instead of maps/sets).
- Unnecessary copying or large intermediate structures.
- Missing caching of expensive, stable results.
- Propose improvements:
- Prefer algorithmic improvements first (reduce complexity).
- Suggest caching only when it's simple and clearly beneficial.
- Avoid premature micro-optimizations.
- Suggest how to verify:
- Add basic benchmarks or timing logs.
- Propose a before/after measurement approach.
- Stay practical:
- If current performance is acceptable, say so instead of over-optimizing.
Examples
User Request: "My Node.js API is slow."
Agent Action/Output:
"Analysis: Profiled the endpoint. 80% of time is spent waiting for 3 sequential DB queries.
Recommendation: Use Promise.all to run them in parallel if they are independent."
// Before (Sequential ~300ms)
const user = await getUser(id);
const posts = await getPosts(id);
const settings = await getSettings(id);
// After (Parallel ~100ms)
const [user, posts, settings] = await Promise.all([
getUser(id),
getPosts(id),
getSettings(id),
]);
User Request: "The React app freezes when typing in the search box."
Agent Action/Output: "Cause: The state update triggers a re-render of the entire list (1000+ items) on every keystroke. Fix:
- Debounce the input handler (wait 300ms).
- Memoize the list component with
React.memo."
Source
git clone https://github.com/k1lgor/virtual-company/blob/main/skills/06-performance-profiler/SKILL.mdView on GitHub Overview
Performance Profiler helps you diagnose slow code by pinpointing hot paths, unnecessary work, and costly algorithms. It emphasizes practical, real-world improvements and avoids premature micro-optimizations.
How This Skill Works
Clarify constraints (latency targets, memory limits). Identify bottlenecks such as nested loops, repeated heavy operations, inefficient data structures, and missing caching. Propose algorithmic and caching improvements in priority order, then verify with lightweight benchmarks and before/after measurements.
When to Use It
- User reports that code is slow or asks to optimize a function or path.
- System shows latency, high CPU/memory usage, scaling concerns, or timeouts.
- Working with loops, large data processing, frequent DB queries, or heavy I/O.
- Need to distinguish genuine bottlenecks from noise and validate improvements.
- Prefer practical, measurement-driven optimizations over micro-optimizations.
Quick Start
- Step 1: Clarify constraints and success metrics (latency targets, SLA, memory caps).
- Step 2: Profile to identify bottlenecks (hot paths, heavy ops, data-structure issues).
- Step 3: Propose improvements (algorithmic changes first, consider caching) and verify with before/after benchmarks.
Best Practices
- Clarify constraints and success criteria before measuring.
- Identify bottlenecks: hot paths, heavy operations, and data-structure problems.
- Prioritize algorithmic improvements first; use caching only when clearly beneficial.
- Add simple benchmarks or timing logs to measure impact.
- Avoid premature optimization and verify improvements with before/after comparisons.
Example Use Cases
- Node.js API is slow due to three sequential DB queries; profile shows they are independent—combine with Promise.all to run in parallel.
- React app freezes while typing in a search box due to rendering a long list on every keystroke; debounce input and memoize list components.
- A sorting task with nested iterations is O(n^2); refactor to a more efficient O(n log n) approach or use a streaming/partitioning technique.
- Repeated expensive computations return stable results; add a simple cache with invalidation to avoid recomputation.
- Large intermediate data structures cause memory spikes; refactor to streaming processing or chunked workloads.