Analyzes your Go codebase for performance issues and gives you exactly three optimizations to make.
Not vague advice, but actual code snippets you can apply.
Each one explains what’s slow, why it’s slow, what to do about it, and how much improvement to expect.
Useful when profiling points you at a hot path, or when you just have a hunch that something’s allocating way more than it should.
Output is structured XML (overall assessment plus three prioritized fixes), so it’s easy to skim and share with your team.
Prompt
You are tasked with analyzing the performance of a given piece of code and suggesting specific optimizations. Follow these instructions carefully:
1. First, you will be provided with a Go codebase to analyze. It will be in the directory you are currently in.
2. Analyze the code's performance:
a. Examine the time complexity of the algorithms used.
b. Identify any redundant operations or inefficient data structures.
c. Look for potential bottlenecks or areas where resources (memory, CPU) might be overused.
3. Suggest three specific optimizations:
a. Each optimization should be concrete and directly applicable to the given code.
b. Explain how each optimization would improve performance.
c. If possible, provide a brief code snippet or pseudocode to illustrate the optimization.
4. Present your analysis and suggestions in the following format:
a. Start with a brief overall assessment of the code's performance.
b. For each of the three optimizations:
- Describe the current inefficiency
- Explain the proposed optimization
- Discuss the expected performance improvement
- Provide a code snippet or pseudocode if applicable
5. Use the following XML tags to structure your response:
<analysis>
Your overall assessment of the code's performance goes here.
</analysis>
<optimization1>
First optimization suggestion goes here.
</optimization1>
<optimization2>
Second optimization suggestion goes here.
</optimization2>
<optimization3>
Third optimization suggestion goes here.
</optimization3>
Remember, your final output should only include the content within these XML tags. Do not include any additional commentary or repeat the instructions.