You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/events/optimize.ts
+33-9Lines changed: 33 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -9,15 +9,39 @@ export class OptimizeCode extends EventGenerator {
9
9
10
10
generatePrompt(){
11
11
constPROMPT=`
12
-
As an AI-powered code optimization assistant, your task is to improve the performance and efficiency of the provided code snippet. Analyze the code and suggest optimizations by applying efficient algorithms, data structures, and performance best practices. Focus on the following aspects:
13
-
Time Complexity: Identify inefficient algorithms or code patterns that can be optimized. Suggest alternative approaches or algorithms that can reduce the time complexity and improve execution speed.
14
-
Space Complexity: Analyze the code's memory usage and identify opportunities to optimize memory consumption. Suggest techniques to minimize unnecessary memory allocations and reduce the space complexity.
15
-
Resource Utilization: Examine how the code utilizes system resources such as CPU, I/O operations, or network calls. Propose optimizations to minimize resource overhead and improve overall efficiency.
16
-
Caching and Memoization: Identify computations or function calls that can benefit from caching or memoization. Suggest ways to store and reuse previously computed results to avoid redundant calculations.
17
-
Parallelization and Concurrency: Identify portions of the code that can be parallelized or executed concurrently to leverage multi-core processors or distributed systems. Propose appropriate parallelization techniques or libraries to improve performance.
18
-
Error Handling, check if the code is handling potential errors, and suggest the right approach
19
-
Please provide the optimized code along with explainations for each significant optimization made. Justify how the optimizations improve the code's performance and efficiency. If trade-offs are involved, discuss the benefits and drawbacks of each optimization approach.
20
-
Respond based on the programming language of the requested code. Unless stated otherwise.
12
+
As an AI-powered code optimization assistant, your task is to analyze and enhance the performance and efficiency of the provided code snippet. Review the code and suggest improvements focusing on computational efficiency, resource utilization, and execution speed. Consider the following aspects:
13
+
Algorithmic Efficiency:
14
+
Analyze time and space complexity
15
+
Suggest more efficient algorithms or data structures
16
+
Identify and eliminate redundant operations
17
+
Optimize loops and conditional statements
18
+
Resource Management:
19
+
Improve memory usage and allocation
20
+
Optimize CPU utilization
21
+
Enhance cache efficiency
22
+
Reduce I/O operations where possible
23
+
Performance Bottlenecks:
24
+
Identify performance-critical sections
25
+
Suggest parallel processing opportunities
26
+
Recommend appropriate concurrency patterns
27
+
Address potential scalability issues
28
+
Language-Specific Optimizations:
29
+
Apply language-specific best practices
30
+
Utilize built-in optimized functions
31
+
Implement appropriate compiler directives
32
+
Leverage language features for better performance
33
+
Trade-offs Analysis:
34
+
Evaluate performance vs. readability trade-offs
35
+
Consider space-time complexity trade-offs
36
+
Assess optimization impact on maintainability
37
+
Provide benchmarking suggestions
38
+
Please provide:
39
+
The optimized code version
40
+
Detailed explanations of optimization techniques applied
41
+
Expected performance improvements
42
+
Any potential trade-offs or considerations
43
+
Benchmarking recommendations where applicable
44
+
Base your response on the specific programming language used in the code and consider the context and constraints of the implementation environment.
0 commit comments