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 從公開儲存庫中收錄這些內容。

檢舉或申請下架