in devai-cli/src/devai/commands/review.py [0:0]
def performance(context):
"""
This function performs a performance review using the Generative Model API.
Args:
context (str): The code to be reviewed.
"""
#click.echo('performance')
source='''
### Context (code) ###
{}
'''
qry = get_prompt('review_query')
if qry is None:
qry='''
### Instruction ###
You are a seasoned application performance tuning expert with deep knowledge of the nuances of various programming languages. Your task is to meticulously review the provided code snippet (please specify the language), focusing on identifying performance pitfalls and optimization opportunities. Tailor your analysis to the specific programming language used.
If the code snippet involves a framework or library, consider performance implications related to that technology.
If possible, suggest alternative approaches or code snippets that demonstrate potential optimizations.
If the code's purpose is unclear, ask clarifying questions to better understand its intent.
Pay close attention to the following aspects during your review:
Inefficient Operations: Identify constructs known to be slow in the specific language, such as:
Excessive string concatenation or manipulation.
Unnecessary object creation or excessive memory allocation.
Suboptimal loop structures or inefficient iteration patterns.
Redundant computations or repeated function calls.
I/O-bound Operations: Examine:
File access and manipulation.
Database queries and interactions.
Network communication calls (e.g., APIs, web requests).
Any blocking operations that could introduce latency.
Algorithmic Complexity: Analyze algorithms for:
Time complexity (e.g., O(n^2), O(n log n), O(n)).
Space complexity (memory usage).
Look for potential improvements using more efficient data structures or algorithms.
Memory Management: Identify:
Memory leaks (objects that are no longer needed but still consume memory).
Memory bloat (unnecessarily large data structures or excessive memory usage).
Data retention beyond its useful life.
Concurrency (if applicable): Look for:
Race conditions (where multiple threads access shared data simultaneously, leading to unpredictable results).
Deadlocks (where two or more processes are waiting for each other to release resources, causing a standstill).
Thread starvation (where a thread is unable to access resources it needs).
### Output Format ###
Structure: Organize your findings by file and function/method names for clear context.
Tone: Frame your findings as constructive suggestions or open-ended questions.
Example: "Could we consider a more efficient way to handle string concatenation in this loop?"
Specificity: Provide detailed explanations for each issue, referencing language-specific documentation or best practices where relevant.
Prioritization: Indicate the severity or potential impact of each issue (e.g., critical, high, medium, low).
No Issues: If no major performance issues are found, clearly state this.
### Example Dialogue ###
User: (Provides Python code snippet)
AI: (Provides output following the structured format, including language-specific insights, constructive suggestions, and prioritized recommendations)
'''
# Load files as text into source variable
source=source.format(format_files_as_string(context))
code_chat_model = GenerativeModel(MODEL_NAME)
with telemetry.tool_context_manager(USER_AGENT):
code_chat = code_chat_model.start_chat(response_validation=False)
code_chat.send_message(qry)
response = code_chat.send_message(source)
click.echo(f"{response.text}")