Introduction
Performance optimization is the art of making your code run faster, use less memory, and scale better without changing its functionality. Every developer faces the moment when an application slows down under load, a query takes seconds instead of milliseconds, or a memory leak crashes the server. In 2026, with distributed systems and AI-assisted development becoming the norm, the ability to quickly identify and fix performance bottlenecks is more valuable than ever.
But where do you start? Profiling, benchmarking, and systematic analysis are the foundations. However, even experienced engineers can waste hours chasing the wrong issue. That's where structured prompts come in — they guide your thinking, your analysis tools, and your code refactoring. This article collects 10 battle-tested prompts I use daily in my workflow. Each prompt is accompanied by a real usage example, so you can apply them immediately to your own projects.
1. The Profiling Kickoff Prompt
Prompt: "Analyze the attached CPU profile flame graph and identify the top three functions consuming more than 10% of execution time. For each, suggest a specific optimization technique (e.g., caching, algorithm change, parallel execution) and estimate the potential speedup factor."
Usage example: You run a Python application that processes 100,000 JSON records. You generate a flame graph using py-spy or cProfile. Feed the image or text output to this prompt. The result: you discover that json.loads takes 40% of time, and the prompt suggests using orjson or simdjson for a 5–10x speedup.
2. The Database Query Deep Dive
Prompt: "Given the following SQL query and its EXPLAIN ANALYZE output, identify the most expensive operation. Suggest index creation, query rewriting, or schema changes. Provide a before/after comparison of execution plans."
Usage example: You have a query joining five tables on an e-commerce site. The prompt points out a sequential scan on a table with 10 million rows. It recommends a composite index on (user_id, created_at) and rewriting the WHERE clause to use a range condition instead of IN. After applying, query time drops from 12 seconds to 0.3 seconds.
3. The Memory Leak Hunter
Prompt: "Analyze this heap dump (or memory snapshot) from a Node.js service. Identify objects that are not being garbage-collected. For each suspected leak, trace the retaining path and suggest a fix. Include a code snippet to reproduce the issue."
Usage example: A background job grows memory until OOM. You use Chrome DevTools or heapdump to capture a snapshot. The prompt finds a Set that accumulates event listeners without removal. It provides a fix: use WeakRef or manually clean up listeners in the 'close' event handler. Memory usage stabilizes at 50 MB instead of growing to 1 GB.
4. The Async Concurrency Optimizer
Prompt: "Review this asynchronous code (Python asyncio / JavaScript async-await) for concurrency bottlenecks. Highlight places where tasks are blocked by I/O or CPU-bound operations. Suggest using asyncio.gather, semaphores, or offloading to a thread pool. Show the rewritten code."
Usage example: A web scraper fetches 1000 URLs sequentially. The prompt rewrites it with asyncio.gather and a semaphore limiting concurrency to 50. Total time drops from 30 minutes to 36 seconds. It also warns about CPU-heavy parsing — it moves that to run_in_executor.
5. The Algorithm Complexity Check
Prompt: "Given this function and its input size (N=100,000), estimate its time and space complexity. If it's worse than O(N log N), suggest an alternative algorithm or data structure. Provide a benchmark comparison with real numbers."
Usage example: You have a function that finds duplicates in an array using nested loops — O(N²). The prompt replaces it with a hash set — O(N). For 100k elements, the runtime goes from 45 seconds to 0.02 seconds. The prompt also shows a memory trade-off: O(N) extra memory vs O(1) but slower alternative.
6. The Network Latency Reducer
Prompt: "Analyze this HTTP request waterfall (from Chrome DevTools or a HAR file). Identify the critical path and suggest optimizations: CDN usage, connection pooling, HTTP/2 multiplexing, or reducing payload size. Provide concrete configuration changes."
Usage example: A React app loads in 8 seconds. The waterfall shows 40 sequential requests. The prompt recommends enabling HTTP/2 on the server, using Link rel="preload" for critical CSS, and combining API calls into a single GraphQL query. Time to interactive drops to 2.5 seconds.
7. The Caching Strategy Prompt
Prompt: "For this read-heavy endpoint (1000 req/s, 80% reads, 20% writes), design a caching layer. Compare options: in-memory cache (Redis), local LRU cache, CDN edge caching. Include invalidation strategy, TTL recommendations, and estimated cache hit ratio."
Usage example: A product catalog API returns JSON. The prompt suggests Redis with a TTL of 300 seconds and a cache-aside pattern. It also warns about thundering herd — adds a mutex for cache rebuild. Cache hit ratio reaches 95%, and average response time falls from 150 ms to 5 ms.
8. The Frontend Rendering Profiler
Prompt: "Analyze this React component's render path using React DevTools Profiler. Identify unnecessary re-renders, heavy computations in render, or large virtual DOM diffs. Suggest React.memo, useMemo, useCallback, or splitting into smaller components."
Usage example: A data table with 500 rows re-renders on every keystroke in a search box. The prompt identifies that the entire table component re-renders because the parent passes an inline arrow function. Applying React.memo on table rows and useCallback on the click handler reduces re-render count from 500 to just 1 per keystroke.
9. The Build and Bundle Analyzer
Prompt: "Given this webpack/rollup bundle analysis report (stats.json), identify the largest modules and suggest code splitting, tree shaking, or dynamic imports. Provide a plan to reduce the bundle size by at least 30%."
Usage example: The production bundle is 2 MB. The prompt finds that moment.js with all locales contributes 500 KB. It recommends replacing it with date-fns (tree-shakeable) and using dynamic imports for admin pages. New bundle size: 1.2 MB. Load time improves from 4.5s to 2.1s.
10. The Full-Stack Performance Review
Prompt: "Perform a holistic performance audit of this web application. Consider: frontend (LCP, FID, CLS), backend (latency p50/p99, throughput), database (slow queries, connection pool), and infrastructure (auto-scaling, CDN). Provide a prioritized action list with estimated impact."
Usage example: You paste in Lighthouse scores, server logs, and DB metrics. The prompt ranks issues: (1) Database missing index on order_date — estimated 40% speed gain, (2) No CDN for static assets — 30% LCP improvement, (3) Unoptimized images — 20% reduction. You implement the top 3 in one sprint, and the app's performance score jumps from 45 to 85.
Conclusion
Performance optimization is not guesswork — it's a systematic process of measurement, analysis, and targeted refactoring. The prompts above serve as a structured guide to that process. They help you ask the right questions, focus on high-impact areas, and avoid premature optimization. Start by integrating one prompt into your next code review or debugging session. Over time, you'll build an intuition for where performance hides and how to release it.
Remember: the best optimization is the one you measure. Always profile before and after. And if you work with APIs, databases, or cloud services, consider using tools that connect your performance data directly to your development workflow. For example, ASI Biont supports connecting performance monitoring tools via API — you can learn more at asibiont.com/courses. Happy optimizing!
Comments