AgentSkillsCN

performance

通过异步模式、缓存策略、性能剖析与资源管理,优化应用性能。在诊断慢速端点、实现缓存层、剖析 CPU/内存瓶颈、优化数据库查询,或搭建性能监控系统时,可使用此技能。

SKILL.md
--- frontmatter
name: "performance"
description: 'Optimize application performance through async patterns, caching strategies, profiling, and resource management. Use when diagnosing slow endpoints, implementing caching layers, profiling CPU/memory bottlenecks, optimizing database queries, or setting up performance monitoring.'
metadata:
  author: "AgentX"
  version: "1.0.0"
  created: "2025-01-15"
  updated: "2025-01-15"

Performance

Purpose: Optimize application speed, throughput, and resource usage for production loads.
Strategy: Profile first, optimize bottlenecks, measure impact.
Note: For language-specific implementations, see C# Development or Python Development.


When to Use This Skill

  • Diagnosing slow application endpoints
  • Implementing caching strategies
  • Profiling CPU or memory bottlenecks
  • Optimizing database query performance
  • Setting up performance monitoring and alerting

Prerequisites

  • Application running in a profiling-capable environment
  • Access to monitoring tools

Decision Tree

code
Performance concern?
├─ Not yet measured? → Profile FIRST (don't guess)
│   ├─ .NET → dotnet-trace / BenchmarkDotNet
│   ├─ Python → cProfile / py-spy
│   └─ Node.js → clinic.js / --prof
├─ Slow API response?
│   ├─ Database query? → EXPLAIN ANALYZE → add index
│   ├─ External service? → Add caching + async calls
│   └─ Computation? → Optimize algorithm or add memoization
├─ High memory usage?
│   ├─ Large collections? → Stream/paginate instead of loading all
│   └─ Memory leaks? → Profile allocations, check dispose patterns
├─ Concurrency bottleneck?
│   ├─ I/O bound? → async/await (don't block threads)
│   └─ CPU bound? → Parallel processing / background workers
└─ Quick wins? → See Quick Wins table below

Quick Wins

OptimizationImpactEffort
Enable Response Compression70-90% size reductionLow
Add Database Indexes10-100x query speedLow
Implement Caching50-99% latency reductionMedium
Use Async I/O5-10x throughputMedium
Fix N+1 Queries10-1000x DB performanceMedium

Performance Anti-Patterns

Anti-PatternProblemSolution
Premature OptimizationOptimize before profilingProfile first, optimize bottlenecks
Over-CachingCache everythingCache strategically based on access patterns
Blocking I/OSynchronous network callsUse async/await
No PaginationLoad all resultsPaginate large datasets
Missing IndexesFull table scansAdd indexes on frequently queried columns
N+1 QueriesLoop over queriesUse JOINs or batch loading

Optimization Checklist

Before Production:

  • Profile application under realistic load
  • Add database indexes on frequently queried columns
  • Implement caching for expensive operations
  • Enable response compression
  • Fix N+1 query problems
  • Use connection pooling
  • Implement async I/O where applicable
  • Paginate large result sets
  • Set up monitoring and alerts
  • Conduct load testing
  • Set performance budgets
  • Optimize static asset delivery

Resources

Profiling Tools:

  • .NET: BenchmarkDotNet, dotTrace, PerfView
  • Python: cProfile, py-spy, Scalene
  • Node.js: clinic.js, 0x, Chrome DevTools
  • Java: JProfiler, VisualVM

Load Testing:

Guides:


See Also: Skills.mdAGENTS.md

Last Updated: January 27, 2026

Scripts

ScriptPurposeUsage
run-benchmark.ps1Run benchmarks (.NET/Python/Node) with baseline comparison./scripts/run-benchmark.ps1 [-Baseline baseline.json]

Troubleshooting

IssueSolution
Cache stampede on expiryUse cache-aside with staggered TTL or background refresh
Memory leak in productionProfile with dotMemory/py-spy, check for unbounded collections
High latency spikesCheck GC pauses, database connection pool, and external service timeouts

References