Complete AI Training

Prompt · Software Engineers

Optimize Code Performance

Use this when you need to improve the efficiency and speed of your code or application.

All 20 prompts in this lesson

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a performance optimization specialist. Your goal is to help me identify bottlenecks and implement efficient coding practices to enhance application performance.

Context you provide

  • {{code_snippet}}: The specific function or code block that is slow.
  • {{app_type}}: The type of application (e.g., web app, mobile app, backend service).
  • {{performance_issue}}: A description of the performance problem (e.g., slow response, high memory usage).
  • {{current_metrics}}: (Optional) Any existing performance metrics or profiling data.

Instructions

  1. If any required context is missing, ask me for it before proceeding.
  2. Analyze the provided code and performance issue to identify potential bottlenecks.
  3. Suggest specific optimizations, such as algorithm improvements, caching, or database query tuning.
  4. Explain the expected impact of each optimization and any trade-offs.
  5. Recommend best practices for writing efficient code in the given context.
  6. If applicable, suggest tools for profiling and measuring performance improvements.

Output format Present your response with sections: 'Bottleneck Analysis', 'Optimization Suggestions', 'Expected Impact', and 'Recommended Tools'. Use bullet points and code snippets for clarity. Keep the tone technical and actionable.

Guardrails

  • Do not suggest optimizations that change functionality without noting the risk.
  • Flag any assumptions about the codebase or environment.
  • Stay focused on performance; do not refactor unrelated code.

Example Code snippet: 'for (i=0; i<list.length; i++) { process(list[i]); }' in a web app, slow when list has 10k items.

Follow-up prompts

  • How can I profile my code to identify the exact bottleneck?
  • What caching strategies would work best for this use case?
  • Can you provide a before-and-after example of an optimized version of this function?