Profiling Optimization

aj-geddes/useful-ai-prompts/skills/profiling-optimization

作者 aj-geddes3f5182cfd739无许可证355 个星标收录于 2026年10月8日更新于 2026年10月8日仓库7个月前更新

Profile application performance, identify bottlenecks, and optimize hot paths using CPU profiling, flame graphs, and benchmarking. Use when investigating performance issues or optimizing critical code paths.

AI 生成的概览

通过 CPU 性能分析、火焰图和基准测试来剖析应用性能、定位瓶颈并优化热点路径。

功能
指导智能体剖析代码执行过程,以数据驱动的方式定位性能瓶颈并优化关键路径。内容涵盖 Node.js 性能分析、Chrome DevTools CPU 配置文件、Python cProfile、基准测试、数据库查询剖析以及火焰图生成。该技能还附带一个验证脚本和一个 API 脚手架模板。
适用场景
适用于排查性能问题、识别 CPU 瓶颈、优化热点路径,或降低延迟、提升吞吐量的场景。
运行要求
会运行可执行脚本(scripts/validate-api.sh),并读取参考指南和模板。剖析目标需要相应的运行时和工具,例如 Node.js、带 cProfile 的 Python、Chrome DevTools,以及用于查询剖析的数据库访问权限。

Profiling & Optimization

Table of Contents

Overview

Profile code execution to identify performance bottlenecks and optimize critical paths using data-driven approaches.

When to Use

  • Performance optimization
  • Identifying CPU bottlenecks
  • Optimizing hot paths
  • Investigating slow requests
  • Reducing latency
  • Improving throughput

Quick Start

Minimal working example:

typescript
import { performance, PerformanceObserver } from "perf_hooks";
class Profiler {  private marks = new Map<string, number>();
  mark(name: string): void {    this.marks.set(name, performance.now());  }
  measure(name: string, startMark: string): number {    const start = this.marks.get(startMark);    if (!start) throw new Error(`Mark ${startMark} not found`);
    const duration = performance.now() - start;    console.log(`${name}: ${duration.toFixed(2)}ms`);
    return duration;  }
  async profile<T>(name: string, fn: () => Promise<T>): Promise<T> {    const start = performance.now();
    try {      return await fn();    } finally {// ... (see reference guides for full implementation)

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
Node.js Profiling [blocked]Node.js Profiling
Chrome DevTools CPU Profile [blocked]Chrome DevTools CPU Profile
Python cProfile [blocked]Python cProfile
Benchmarking [blocked]Benchmarking
Database Query Profiling [blocked]Database Query Profiling
Flame Graph Generation [blocked]Flame Graph Generation

Best Practices

✅ DO

  • Profile before optimizing
  • Focus on hot paths
  • Measure impact of changes
  • Use production-like data
  • Consider memory vs speed tradeoffs
  • Document optimization rationale

❌ DON'T

  • Optimize without profiling
  • Ignore readability for minor gains
  • Skip benchmarking
  • Optimize cold paths
  • Make changes without measurement

来源与署名

来源:aj-geddes/useful-ai-prompts位于skills/profiling-optimization提交3f5182c

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架