File contents 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:
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:
Guide
Contents
Node.js Profiling
Node.js Profiling
Chrome DevTools CPU Profile
Chrome DevTools CPU Profile
Python cProfile
Python cProfile
Benchmarking
Benchmarking
Database Query Profiling
Database Query Profiling
Flame Graph Generation
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
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1 --- 2 name: aj-geddes-useful-ai-prompts-profiling-optimization 3 description: Profiling & Optimization 4 --- 5 6 # Profiling & Optimization 7 8 ## Table of Contents 9 10 - [Overview](#overview) 11 - [When to Use](#when-to-use) 12 - [Quick Start](#quick-start) 13 - [Reference Guides](#reference-guides) 14 - [Best Practices](#best-practices) 15 16 ## Overview 17 18 Profile code execution to identify performance bottlenecks and optimize critical paths using data-driven approaches. 19 20 ## When to Use 21 22 - Performance optimization 23 - Identifying CPU bottlenecks 24 - Optimizing hot paths 25 - Investigating slow requests 26 - Reducing latency 27 - Improving throughput 28 29 ## Quick Start 30 31 Minimal working example: 32 33 ```typescript 34 import { performance, PerformanceObserver } from "perf_hooks"; 35 36 class Profiler { 37 private marks = new Map<string, number>(); 38 39 mark(name: string): void { 40 this.marks.set(name, performance.now()); 41 } 42 43 measure(name: string, startMark: string): number { 44 const start = this.marks.get(startMark); 45 if (!start) throw new Error(`Mark ${startMark} not found`); 46 47 const duration = performance.now() - start; 48 console.log(`${name}: ${duration.toFixed(2)}ms`); 49 50 return duration; 51 } 52 53 async profile<T>(name: string, fn: () => Promise<T>): Promise<T> { 54 const start = performance.now(); 55 56 try { 57 return await fn(); 58 } finally { 59 // ... (see reference guides for full implementation) 60 ``` 61 62 ## Reference Guides 63 64 Detailed implementations in the `references/` directory: 65 66 | Guide | Contents | 67 |---|---| 68 | [Node.js Profiling](references/nodejs-profiling.md) | Node.js Profiling | 69 | [Chrome DevTools CPU Profile](references/chrome-devtools-cpu-profile.md) | Chrome DevTools CPU Profile | 70 | [Python cProfile](references/python-cprofile.md) | Python cProfile | 71 | [Benchmarking](references/benchmarking.md) | Benchmarking | 72 | [Database Query Profiling](references/database-query-profiling.md) | Database Query Profiling | 73 | [Flame Graph Generation](references/flame-graph-generation.md) | Flame Graph Generation | 74 75 ## Best Practices 76 77 ### ✅ DO 78 79 - Profile before optimizing 80 - Focus on hot paths 81 - Measure impact of changes 82 - Use production-like data 83 - Consider memory vs speed tradeoffs 84 - Document optimization rationale 85 86 ### ❌ DON'T 87 88 - Optimize without profiling 89 - Ignore readability for minor gains 90 - Skip benchmarking 91 - Optimize cold paths 92 - Make changes without measurement 93 94 --- 95 > Converted and distributed by [TomeVault](https://tomevault.io/claim/aj-geddes) — claim your Tome and manage your conversions. 96 <!-- tomevault:4.0:skill_md:2026-04-11 -->
tomevault-io/skills-registry/tree/main/aj-geddes--useful-ai-prompts--profiling-optimization commit 47d8a0edda
Frequently asked questions How do I install the Aj Geddes Useful AI Prompts Profiling Optimization skill? Run npx skillmds@latest add tomevault-io/aj-geddes-useful-ai-prompts-profiling-optimization in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
What does the Aj Geddes Useful AI Prompts Profiling Optimization skill do? Profiling & Optimization It is listed under Coding & Dev Tools on SkillMD.
Is Aj Geddes Useful AI Prompts Profiling Optimization safe to use? This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
Which AI agents work with Aj Geddes Useful AI Prompts Profiling Optimization? This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Is Aj Geddes Useful AI Prompts Profiling Optimization free to use? Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Who published Aj Geddes Useful AI Prompts Profiling Optimization? tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.