20 tested prompts across 4 stages. Works with ChatGPT, Claude, and Gemini.

Identify and fix performance bottlenecks in your codebase using Cursor to deliver faster applications. Built across 4 distinct stages covering Profile and measure, Optimize algorithms, Optimize I/O and async and more, this guide gives you one tested prompt per step so you never have to write from scratch or guess what the AI needs. The prompts work in ChatGPT, Claude, and Gemini and are designed to get usable output on the first try.
Stage 1
Start here to identify where performance is actually slow before optimising anything.
Find the bottleneck
My application is slow in [DESCRIBE WHERE: PAGE LOAD / API RESPONSE / SPECIFIC FUNCTION]. Help me instrument the code to find the bottleneck: [PASTE CODE]. What should I measure and how?
Measure function performance
Write code to measure the performance of this function: [PASTE FUNCTION]. Use [CONSOLE.TIME / PERFORMANCE.NOW / THE APPROPRIATE PROFILING TOOL FOR MY LANGUAGE]. Show how to log results.
Analyze a slow API route
This API route is responding too slowly: [PASTE ROUTE HANDLER]. Walk me through how to profile it: timing each database call, each computation, and each external call to find where the time is going.
Read a performance profile
Help me interpret this performance profile output: [PASTE PROFILE RESULTS]. What are the hottest functions? What should I optimize first based on time spent and call frequency?
Set performance budgets
Help me set realistic performance targets for [TYPE OF APP: WEB APP / API / CLI]. What are good benchmarks for [PAGE LOAD TIME / API LATENCY / FUNCTION EXECUTION TIME] based on current best practices?
Stage 2
These prompts help you improve algorithmic efficiency and reduce unnecessary computation.
Improve time complexity
This code is O(n²) or worse due to nested loops: [PASTE CODE]. Rewrite it to be more efficient. Explain the complexity of the original and the improved version.
Optimize data structure choice
I'm using [ARRAY / OBJECT / SET / MAP] for [DESCRIBE THE OPERATION]. Am I using the right data structure for this use case? What is the time complexity of my current operations and what should I use instead?
Remove redundant computation
This code is computing the same value multiple times: [PASTE CODE]. Refactor to compute it once and reuse the result. Add memoization if it is called repeatedly with the same inputs.
Optimize string operations
This code does a lot of string operations that are slow: [PASTE CODE]. Rewrite to use more efficient string handling: string builders, avoiding repeated concatenation, or batch operations.
Implement caching
Add memoization or caching to this function that is called repeatedly with the same inputs: [PASTE FUNCTION]. Use [SIMPLE OBJECT CACHE / LRU CACHE / REDIS] and handle cache invalidation.
Stage 3
Use these prompts to reduce latency from network calls, file I/O, and async operations.
Parallelize async operations
These async operations run sequentially but could run in parallel: [PASTE CODE]. Rewrite using Promise.all or equivalent to run them concurrently. Show the time savings.
Eliminate N+1 queries
I have an N+1 query problem: [PASTE CODE SHOWING THE LOOP WITH A QUERY INSIDE]. Rewrite to fetch all needed data in one or two queries using JOINs, batch fetching, or DataLoader.
Add database indexes
These database queries are slow: [PASTE QUERIES]. What indexes should I add? Show the CREATE INDEX statements and explain how each index helps the specific query.
Stream large data
This code loads a large dataset into memory at once: [PASTE CODE]. Rewrite it to process the data as a stream so memory usage stays flat even for large datasets.
Batch API calls
My code makes an API call for each item in a loop: [PASTE CODE]. Rewrite it to batch the API calls, using the API's batch endpoint if available, or processing in chunks of [N] items.
Stage 4
These prompts help you improve page load speed, rendering performance, and Core Web Vitals.
Reduce bundle size
Analyze this code for bundle size optimizations: [PASTE IMPORTS AND CODE]. Identify: unused imports, large libraries with lighter alternatives, and code that should be lazy-loaded.
Optimize React rendering
This React component re-renders too often: [PASTE COMPONENT]. Identify the causes and fix them using: React.memo, useMemo, useCallback, or state restructuring.
Improve Core Web Vitals
Help me improve [LCP / CLS / INP / FID] for this page: [DESCRIBE OR PASTE THE PAGE CODE]. What are the most impactful changes I can make to improve this specific metric?
Optimize images
Review the image loading in this page: [PASTE CODE]. Suggest: correct image formats, lazy loading, proper sizing, and CDN delivery strategies to minimize image-related performance issues.
Defer non-critical resources
Help me identify which JavaScript, CSS, and third-party scripts in this page are non-critical: [PASTE OR DESCRIBE]. Show how to defer or lazy-load each without breaking functionality.
Measure first, optimize second. Without profiling, you will optimize the wrong thing. The 80/20 rule applies: 20% of the code causes 80% of the slowness. Profile to find the 20% before writing a single line of optimization code.
N+1 database query patterns, missing indexes, sequential async operations that could run in parallel, redundant computation in loops, and oversized JavaScript bundles. These account for the majority of application-level slowness.
Define performance goals based on user experience: page loads under 2 seconds, API responses under 200ms, etc. Optimize until you meet the goal, then stop. Premature optimization is the root of much unnecessary complexity.
Yes. Paste your slow queries and Cursor will suggest indexes, query rewrites, and caching strategies. It can also help you read EXPLAIN output to understand how the database is executing your queries.
Rarely. Micro-optimization (shaving microseconds off individual operations) almost never moves the needle on user-perceived performance. Focus on architectural improvements: fewer database queries, parallelized I/O, and reduced bundle sizes.
AI Prompts for Cursor for Debugging
Debugging code can be time-consuming and frustrating for developers.
See promptsAI Prompts for Cursor for SQL
Write, debug, and optimize SQL queries faster using Cursor to work with databases more effectively..
See promptsAI Prompts for Cursor for Backend Development
Build scalable, maintainable backend systems faster using Cursor's AI assistance for APIs, services, and data layers..
See prompts