AgentSkillsCN

code-optimizer

分析代码中的性能问题,并提出优化建议。当用户询问“如何优化这段代码”、“查找性能瓶颈”、“提升运行效率”、“排查内存泄漏”、“评估代码效率”,或希望识别计算瓶颈、算法优化空间、缓存利用机会,乃至并发问题时,这一工具将为你提供专业支持。

SKILL.md
--- frontmatter
name: code-optimizer
description: Analyze code for performance issues and suggest optimizations. Use when users ask to "optimize this code", "find performance issues", "improve performance", "check for memory leaks", "review code efficiency", or want to identify bottlenecks, algorithmic improvements, caching opportunities, or concurrency problems.

Code Optimization

Analyze code for performance issues following this priority order:

Analysis Priorities

  1. Performance bottlenecks - O(n²) operations, inefficient loops, unnecessary iterations
  2. Memory leaks - unreleased resources, circular references, growing collections
  3. Algorithm improvements - better algorithms or data structures for the use case
  4. Caching opportunities - repeated computations, redundant I/O, memoization candidates
  5. Concurrency issues - race conditions, deadlocks, thread safety problems

Workflow

  1. Read the target code file(s)
  2. Identify language and framework context
  3. Analyze for each priority category
  4. Report findings with severity and fixes

Response Format

For each issue found:

code
### [Severity] Issue Title
**Location**: file:line_number
**Category**: Performance | Memory | Algorithm | Caching | Concurrency

**Problem**: Brief explanation of the issue

**Impact**: Why this matters (performance cost, resource usage, etc.)

**Fix**:
[Code example showing the optimized version]

Severity Levels

  • Critical: Causes crashes, severe memory leaks, or O(n³)+ complexity
  • High: Significant performance impact (O(n²), blocking operations, resource exhaustion)
  • Medium: Noticeable impact under load (redundant operations, suboptimal algorithms)
  • Low: Minor improvements (micro-optimizations, style improvements with perf benefit)

Language-Specific Checks

JavaScript/TypeScript

  • Array methods inside loops (map/filter/find in forEach)
  • Missing async/await causing blocking
  • Event listener leaks
  • Unbounded arrays/objects

Python

  • List comprehensions vs generator expressions for large data
  • Global interpreter lock considerations
  • Context manager usage for resources
  • N+1 query patterns

General

  • Premature optimization warnings (only flag if genuinely impactful)
  • Database query patterns (N+1, missing indexes)
  • I/O in hot paths