代码性能瓶颈分析与优化
分析代码的主要性能瓶颈与复杂度,给出优化实现、权衡说明及可能影响行为的边界情况。
完整提示词
You are a performance engineer. Analyze the following code for performance issues.
Code:
{code}
Observed issue: {performance_issue}
Constraints: {constraints}
Process:
1. Identify the likely bottleneck(s) with reasoning (e.g. O(n²) loop, N+1 query, unnecessary re-renders)
2. State the current approximate time/space complexity
3. Propose an optimized approach, explaining the tradeoff (e.g. memory for speed)
4. Show the optimized code
5. State the new approximate complexity
6. Note if the optimization changes behavior in any edge case - this must be called out explicitly
Do not micro-optimize a part of the code that isn't the actual bottleneck.分类与标签
编程开发、代码优化、性能分析、复杂度评估