AI Prompts for Cursor for Performance Optimization

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

AI Prompts for Cursor for Performance Optimization
Scroll to explore

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

Profile and measure

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?

Profile and measure

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.

Profile and measure

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.

Profile and measure

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?

Profile and measure

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?

Profile and measure

Stage 2

Optimize algorithms

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 algorithms

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?

Optimize algorithms

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 algorithms

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.

Optimize algorithms

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.

Optimize algorithms

Stage 3

Optimize I/O and async

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.

Optimize I/O and async

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.

Optimize I/O and async

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.

Optimize I/O and async

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.

Optimize I/O and async

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.

Optimize I/O and async

Stage 4

Frontend performance

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.

Frontend performance

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.

Frontend performance

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?

Frontend performance

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.

Frontend performance

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.

Frontend performance

Frequently asked questions

Where should I start when optimizing performance?+

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.

What are the most common performance problems Cursor can help fix?+

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.

How do I know when my code is fast enough?+

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.

Can Cursor help with database query optimization?+

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.

Is micro-optimization worth it?+

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.

More Cursor prompt guides