Prompt Coding Limited info

Code Performance Optimizer

A prompt that asks an AI to refactor code specifically for better performance, identifying bottlenecks and suggesting more efficient algorithms, data structures, or patterns.

  • 🤖 ChatGPT, Claude, Gemini
  • 🗂️ Coding

Prompt by PickleBoxer · Original source (opens in a new tab)

Code Performance Optimizer — prompt preview

The prompt

prompt
Refactor the following code to improve performance:

[INSERT YOUR CODE HERE]

What it is

Code Performance Optimizer is a prompt that focuses the AI's attention specifically on performance improvements. Unlike a general code review, this prompt asks the AI to look at the code through the lens of speed and efficiency: redundant iterations, expensive operations, suboptimal data structures, unnecessary memory allocations, and similar issues. This prompt is valuable when you have code that works correctly but runs too slowly -- perhaps a loop that processes thousands of records, an API handler under heavy load, or a data pipeline with growing latency. Pasting the code with this prompt gives you concrete suggestions for improvement. The prompt is language-agnostic and works with any codebase. For best results, provide context about your performance constraints and data scale. The AI's suggestions should always be validated with actual benchmarks, since theoretical improvements do not always translate to real-world gains.

Who it's for

  • Developers
  • Backend engineers and anyone working on performance-critical code

Requirements

Requirements

  • Any AI chatbot (ChatGPT, Claude, Gemini)

برومبت يطلب من الذكاء الاصطناعي إعادة هيكلة الكود لتحسين الأداء عبر اقتراح خوارزميات وهياكل بيانات أكثر كفاءة.

Examples

From the source

Prompt
prompt
Refactor the following code to improve performance:

[INSERT YOUR CODE HERE]

Expected output: From PickleBoxer's dev-chatgpt-prompts collection on GitHub.

Pros & cons

Pros

  • Pro:Can spot common performance antipatterns like N+1 loops, unnecessary copies, or inefficient string operations
  • Pro:Useful for developers who are not performance specialists but need to optimize a hot path

Cons

  • Con:Without runtime profiling data, the AI may optimize code that is not actually a bottleneck
  • Con:Performance suggestions may sacrifice readability, so you need to weigh the trade-off

Tips

  • Mention the scale of your data (number of records, request frequency) so the AI can calibrate its suggestions
  • Ask the AI to explain the Big-O complexity before and after each change
  • Always benchmark the optimized code in your actual environment -- theoretical improvements do not always hold in practice