Profiling Optimization

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

by aj-geddes3f5182cfd739No license355 starsListed Oct 8, 2026Updated Oct 8, 2026Repository updated 7 months ago

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-generated overview

Profiles application performance to find bottlenecks and optimize hot paths using CPU profiling, flame graphs, and benchmarking.

What it does
Guides an agent through profiling code execution to locate performance bottlenecks and optimize critical paths with a data-driven approach. It covers Node.js profiling, Chrome DevTools CPU profiles, Python cProfile, benchmarking, database query profiling, and flame graph generation. It also ships a validation script and an API scaffold template.
When to use it
Use it when investigating performance issues, identifying CPU bottlenecks, optimizing hot paths, or reducing latency and improving throughput.
Requirements
Runs executable scripts (scripts/validate-api.sh) and reads reference guides and a template. Profiling targets require the relevant runtimes and tools, such as Node.js, Python with cProfile, Chrome DevTools, and database access for query profiling.

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

Source and attribution

Source:aj-geddes/useful-ai-promptsinskills/profiling-optimizationat commit3f5182c

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal