Code performance review prompt: find bottlenecks
Paste code to get bottlenecks identified with their complexity impact, plus concrete optimizations and their trade-offs.
متى تستخدم هذا البرومبت
- When a function or endpoint is measurably slow.
- Before scaling a system to significantly more load.
- When reviewing a hot path flagged by profiling.
نص البرومبت
Review this {{language}} code for performance issues, focusing on {{focus}}. Identify bottlenecks, their complexity impact, and suggest concrete optimizations with trade-offs.
{{CLIPBOARD}}{{language}}{{focus}}{{CLIPBOARD}}الكتلة {{CLIPBOARD}} تُستبدل تلقائياً بما نسخته قبل الضغط على «نسخ».
كيف تستخدمه
- انسخ البرومبت بالزر أو املأ المتغيرات أولاً.
- الصقه في ChatGPT أو Claude أو Gemini.
- عدّل النتيجة أو أعد الطلب بتغيير المتغيرات.
مثال على النتيجة
Bottleneck: nested loop over items and orders is O(n*m); with 10k items this is ~100M comparisons. Fix: build a Map keyed by order.itemId first, then look up in O(1) per item. Trade-off: uses more memory to hold the map, but drops runtime from O(n*m) to O(n+m).
نصائح للاستخدام
- Mention real data sizes (rows, requests/sec) so severity is judged correctly.
- If you have profiler output, paste it alongside the code for a much sharper diagnosis.
- Ask it to rank suggestions by impact vs. effort if you got several.
النماذج الموصى بها
Claude
أسئلة شائعة
- Does it need profiling data to work?
- No, it can reason from code structure alone, but real profiling numbers make the diagnosis far more precise.
- Will suggested fixes always be safe to apply?
- Treat them as candidates to test, not guaranteed-safe changes; benchmark before and after in your actual environment.