Description
This skill inspects the selected code for performance bottlenecks and proposes a refactored version that is more efficient and scalable.
When to use
- •A function or component feels slow or heavy.
- •You see repeated computations or large loops.
- •You suspect N+1 database queries or unnecessary re-renders.
Instructions
- •Analyze the selected code for:
- •Unnecessary re-renders (React components).
- •N+1 query patterns or inefficient database access.
- •Heavy synchronous computations on the main thread.
- •Memory leaks or unnecessary object retention.
- •Explain the main performance issues found.
- •Propose a refactored version of the code that:
- •Reduces time complexity where possible.
- •Minimizes redundant computations or network calls.
- •Uses appropriate memoization, batching, or pagination techniques.
- •Clearly state:
- •Before vs after complexity (e.g. O(n²) to O(n)).
- •Any trade-offs introduced by the refactor.
- •Ensure the refactored code stays readable and maintainable.
Examples
Example input (user intent)
Refactor this list rendering logic; it feels slow on large datasets.
Example output (high level)
- •Explanation of why the current implementation is slow.
- •Refactored React component using virtualization or memoization.
- •Note on expected performance improvement.