AGENT SKILL

performance-expert

Systematic profiling with observability tools (pprof, async-profiler, py-spy): hot path identification, memory allocation and garbage collection analysis, N+1 query optimization, multi-level cache implementation, connection pooling, and kernel tuning for low-latency workloads. Use when reducing P99 latency, analyzing flamegraphs, fixing memory leaks, optimizing slow database queries, reducing CPU usage, improving throughput, or tuning garbage collection. Trigger: performance, profiling, flamegraph, GC tuning, p99 latency. Do NOT trigger for: UI design, frontend development, database schema design, PostgreSQL-specific N+1/SQL optimization (use postgres-database-expert).

License 许可
MIT
最近更新
2026-08-27
Stars
★ 1
Forks
0

01 前言 Front Matter

name
performance-expert
license
MIT
metadata
{ "author": "Community", "status": "stable", "version": "1.0", "category": "quality" }
description
Systematic profiling with observability tools (pprof, async-profiler, py-spy): hot path identification, memory allocation and garbage collection analysis, N+1 query optimization, multi-level cache implementation, connection pooling, and kernel tuning for low-latency workloads. Use when reducing P99 latency, analyzing flamegraphs, fixing memory leaks, optimizing slow database queries, reducing CPU usage, improving throughput, or tuning garbage collection. Trigger: performance, profiling, flamegraph, GC tuning, p99 latency. Do NOT trigger for: UI design, frontend development, database schema design, PostgreSQL-specific N+1/SQL optimization (use postgres-database-expert).

02 资源文件 3

03 SKILL.md 正文

Performance Expert

Profiling, flamegraphs, memory leaks, N+1 queries and GC tuning.

Performance Analysis Stack

Language CPU Profiling Memory Profiling Tracing
Go pprof, go tool trace pprof (-alloc_objects) OTEL spans
Python py-spy, cProfile memray, tracemalloc OTEL spans
JVM async-profiler, JFR jmap, MAT OTEL + JFR
Node clinic.js, 0x heapdump OTEL spans

Profiling Workflow

  1. Establish baseline — current p50/p99 latency + throughput
  2. Profile CPU — identify hot paths consuming >5% of CPU
  3. Profile memory — find allocations, check GC pressure
  4. Trace latency — find wait time (DB, network, locks)
  5. Fix top bottleneck — measure impact before moving to next
  6. Re-baseline — verify improvement, detect regressions

Common Patterns

Bottleneck Fix
N+1 queries Batch load with IN clause, preload associations
Repeated allocations Object pooling, pre-allocation
GC pressure Reduce allocation rate, tune GC
Connection exhaustion Connection pooling, connection reuse
Serialization overhead Streaming parsers, binary formats
Lock contention Reduce lock scope, use lock-free structures

Caching Strategy

L1: In-memory (application cache, TTL: seconds)
L2: Redis/Valkey (distributed cache, TTL: minutes)
L3: CDN (static assets, TTL: hours/days)
  • Cache aside: app checks cache, fills on miss
  • Write-through: app writes to cache + store
  • NEVER cache user-specific PII data in shared caches

Constraints

  • NEVER optimize without profiling first (measure, don't guess)
  • NEVER micro-optimize non-hot paths (focus on >5% CPU consumers)
  • NEVER add caching without measuring hit rate impact
  • ALWAYS re-baseline after optimization (verify improvement)
  • ALWAYS test under production-like load (not local only)
  • NEVER sacrifice correctness for performance

Security

  • NEVER cache PII in shared caches — follow ../engineering-standards/references/security-practices.md PII rules
  • ALWAYS isolate per-user cached data; encrypt at rest when user-derived values are cached
  • ALWAYS keep validation and authz checks intact when optimizing hot paths

Overview

Systematic performance profiling and optimization covering CPU profiling (pprof, py-spy, async-profiler), memory analysis, GC tuning, N+1 query detection, multi-level caching strategies (L1 in-memory, L2 Redis, L3 CDN), and connection pooling. Focused on reducing P99 latency and improving throughput for cloud-native services.

Anti-patterns

FAIL: Optimizing without profiling first

// Premature: optimizing a function that runs 0.1% of CPU
func fastPath() { ... }

PASS: Always profile before optimizing — measure, don't guess

go tool pprof -http=:8080 http://localhost:6060/debug/pprof/profile

FAIL: Adding caching without measuring hit rate impact

cache.Set(key, value) // no hit/miss tracking

PASS: Always instrument cache with hit/miss counters

if val, ok := cache.Get(key); ok {
    metrics.CacheHits.Inc()
} else {
    metrics.CacheMisses.Inc()
}

FAIL: Micro-optimizing non-hot paths while hot path remains unoptimized

Optimizing string concat in a function called 10x/day
while a DB query running 10,000x/min has no index.

PASS: Focus on the top 5% CPU consumers

Profile → identify top consumer → fix → re-profile → repeat

FAIL: Sacrificing correctness for performance

func processRequest(value float64) {
    // skip validation to make it faster
}

PASS: Keep validation; optimize the real bottleneck

func processRequest(value float64) error {
    if value <= 0 { return ErrInvalidValue }
    ...
}

References

Resource URL Last verified
Go pprof documentation https://go.dev/blog/pprof 2026-04
py-spy profiling tool https://github.com/benfred/py-spy 2026-04
async-profiler for JVM https://github.com/async-profiler/async-profiler 2026-03
Clinic.js for Node.js https://clinicjs.org/ 2026-03

Verification Checklist

  • [ ] Baseline p50/p99 latency and throughput established before any optimization
  • [ ] CPU profile collected to identify hot paths (>5% CPU consumers)
  • [ ] Memory profile analyzed for allocation rate and GC pressure
  • [ ] N+1 queries detected and resolved (batch loading, preloaded associations)
  • [ ] Re-baseline measurement taken after each optimization to verify improvement
  • [ ] Caching added only after measuring miss rate and hit ratio
  • [ ] No optimization performed on non-hot paths (focus on top consumers)
  • [ ] PII never cached in shared caches; security-practices PII rules applied

Troubleshooting

Symptom Likely cause Fix
p99 latency spikes every 2 minutes GC cycle — high allocation rate causing frequent GC pauses Reduce allocation rate (object pooling); tune GC frequency with GOGC or JVM flags
Throughput flat despite low CPU Lock contention blocking goroutines/threads Profile with mutex profiler; reduce lock scope; use lock-free structures
Cache hit rate < 50% TTL too short or cache key not matching access patterns Extend TTL; review cache key design; use write-through instead of cache-aside
Profiling in production causes <1% latency overhead (known issue with async-profiler safemode) async-profiler safemode adds safety instrumentation overhead Use --safemode=0 or profile staging environment first

| [WARN] pprof heap profile shows live objects but GC already freed them (gotcha: GC vs profiler timing) | pprof samples heap at time of allocation; objects may be freed between allocation and profile read | Take multiple samples at different GC cycles; use runtime.GC() before allocating to isolate new objects |

04 同仓库更多 Skills

ronsilver
ronsilver/agent-covenant

web-browsing-agent-expert

Web browsing for AI agents: driving a headless browser (Playwright, Puppeteer) from agent tooling, navigation and page-state grounding, DOM extraction and structured data capture, form interaction, session and cookie management, anti-bot mitigation awareness, and safe browsing rules (no PII exfiltration, respect robots and terms). Use when building a browsing tool or MCP server for an agent, teaching an agent to navigate and read web pages, extracting structured content from dynamic sites, or handling login walls and pagination in agent workflows. Trigger: web browsing agent, headless browser, Playwright MCP, Puppeteer, browser automation for agents, DOM extraction, page navigation, session management. Do NOT trigger for: end-to-end UI testing of an application (use playwright-expert); writing standalone scraping scripts for data pipelines (use python-expert); fetching a single public URL (use the fetch tool).

★ 1
ronsilver
ronsilver/agent-covenant

vector-databases

Design and operate vector databases for cloud-native AI features. Use when selecting between pgvector, Pinecone, or Weaviate for AI context layer or integration-hub; designing embedding schemas and index parameters; implementing ANN search with metadata filtering; managing embedding model versions; optimizing query latency; or debugging low retrieval quality. Pairs with rag-architecture for pipeline design and postgres-database-expert for pgvector specifics. Trigger: vector database, pgvector, Pinecone, Weaviate, embedding, ANN search, HNSW, cosine similarity. Do NOT trigger for: relational SQL optimization, standard PostgreSQL schema design, Redis caching.

★ 1
ronsilver
ronsilver/agent-covenant

typescript-expert

Full-stack TypeScript stack for modern projects: frontend SSR/CSR with Next.js 14 App Router and React, backend APIs with Node.js (Express/Fastify), state management with Zustand/Redux Toolkit, unit and integration testing with Vitest/Jest + React Testing Library + MSW, and static analysis with ESLint/Prettier/tsc. Use when building React components or hooks, implementing Next.js App Router or Server Components, writing Node.js REST API handlers, implementing middleware (auth, rate-limit, logging), managing client state (Zustand/RTK), writing frontend/backend tests, or running TypeScript linting/type checks. Trigger: TypeScript, Next.js, React, Zustand, Node.js, Express, Fastify, MSW, Vitest. Do NOT trigger for: Python backend development, Go microservices, iOS/mobile development.

★ 1
ronsilver
ronsilver/agent-covenant

tool-usage

Guide correct tool selection, design, and orchestration for AI agents. Use when choosing between dedicated vs Bash tools, designing MCP tool interfaces, naming tool parameters, handling tool response limits, orchestrating parallel vs sequential calls, evaluating tool accuracy, applying ACI design principles, selecting workflow patterns, or reading/filtering/transforming/generating structured data (JSON, YAML, CSV, TOML, XML). Trigger: tool selection, MCP tool design, orchestration, ACI, parallel execution, composite tool, structured data, jq, yq, dasel, mlr, csvkit. Do NOT trigger for: writing application business logic, domain-specific development (route to domain skill), database migrations.

★ 1
ronsilver
ronsilver/agent-covenant

token-efficiency

Enforce token-efficient output, compression, caching, and model routing. Use when calibrating response verbosity, applying compression strategies to logs or RAG chunks, routing tasks to the right model tier, setting thinking budgets, enforcing word limits, compressing context before reinitiation, applying KV-cache ordering, masking tool output observations, or applying clarification-first protocol before irreversible actions. Trigger: token efficiency, compression, model routing, thinking budget, KV-cache, clarification protocol. Do NOT trigger for: non-agent tooling, CI/CD pipeline scripting, infrastructure provisioning.

★ 1
ronsilver
ronsilver/agent-covenant

time-series-db

Time-series database patterns for cloud-native metrics and analytics: TimescaleDB, InfluxDB, and Amazon Timestream selection; continuous aggregates, retention policies, downsampling, and integration with Prometheus/Grafana. Use when storing business metrics over time, building custom business dashboards, designing high-frequency event storage, or querying time-bucketed aggregations. Trigger: time-series, TimescaleDB, InfluxDB, Prometheus, Grafana, hypertable, continuous aggregate, retention policy. Do NOT trigger for: relational PostgreSQL schema design, NoSQL document stores, Kafka event streaming.

★ 1