AgentSkillsCN

performance-optimizing

识别并修复性能瓶颈。当优化代码性能、修复慢操作,或被要求提升速度时使用。

SKILL.md
--- frontmatter
name: 'performance-optimizing'
description: 'Identifies and fixes performance bottlenecks. Use when optimizing code performance, fixing slow operations, or when asked to improve speed.'
<!-- PromptScript 2026-01-27T13:03:51.815Z - do not edit -->

Performance Optimizing

Optimization Workflow

  1. Measure first - Don't optimize without data
  2. Find bottlenecks - Profile to identify hot paths
  3. Fix the biggest issue - Pareto principle (80/20)
  4. Measure again - Verify improvement
  5. Document - Record what changed and why

Common Bottlenecks

Database

ProblemSolution
N+1 queriesEager loading, batching
Missing indexesAdd indexes on WHERE/JOIN columns
Full table scansOptimize queries, add indexes
Over-fetchingSelect only needed columns
typescript
// Bad - N+1 queries
for (const user of users) {
  const posts = await db.posts.findByUserId(user.id);
}

// Good - single query with join
const usersWithPosts = await db.users.findAll({
  include: ['posts'],
});

Memory

ProblemSolution
Memory leaksClear references, use WeakMap
Large objectsStream processing, pagination
Duplicated dataNormalize, use references

CPU

ProblemSolution
Blocking operationsUse async/workers
Redundant computationMemoization, caching
Inefficient algorithmsBetter data structures
typescript
// Bad - O(n) lookup on every iteration
for (const item of items) {
  if (list.includes(item.id)) { ... }
}

// Good - O(1) lookup with Set
const idSet = new Set(list);
for (const item of items) {
  if (idSet.has(item.id)) { ... }
}

Network

ProblemSolution
Too many requestsBatching, HTTP/2
Large payloadsCompression, pagination
No cachingHTTP caching, CDN

Quick Wins

  1. Add indexes on frequently queried columns
  2. Enable compression (gzip/brotli)
  3. Implement caching at appropriate layers
  4. Use pagination for large datasets
  5. Lazy load non-critical resources

Anti-Patterns

  • Premature optimization without measurement
  • Micro-optimizations that hurt readability
  • Caching everything (cache invalidation is hard)
  • Optimizing cold paths