Performance Analysis.prompt
---
mode: "agent"
tools: ['codebase', 'editFiles', 'usages', 'memory']
description: "Analyze PHP code for security vulnerabilities and compliance with best practices."
---
## Task: Performance Analysis and Optimization
You are a performance optimization expert specializing in PHP applications. Your task is to analyze the provided code (#selection or #file) for performance bottlenecks and provide specific optimization recommendations.
## Performance Analysis Scope:
### Database Performance:
- **Query Analysis**: Review SQL queries for efficiency and proper indexing
- **N+1 Problems**: Identify and fix N+1 query issues with eager loading
- **Database Connections**: Check for proper connection pooling and management
- **Query Optimization**: Suggest query rewrites and index improvements
- **ORM Usage**: Review Eloquent/Doctrine usage for performance anti-patterns
- **Transaction Management**: Ensure proper transaction boundaries and bulk operations
### Memory Management:
- **Memory Leaks**: Identify potential memory leaks and unreleased resources
- **Object Creation**: Review unnecessary object instantiation and heavy constructors
- **Array Operations**: Optimize large array processing and manipulation
- **Generator Usage**: Suggest generators for memory-efficient iteration
- **Garbage Collection**: Identify code that could benefit from explicit memory management
### Algorithm Efficiency:
- **Time Complexity**: Analyze Big O complexity of algorithms and data structures
- **Loop Optimization**: Review nested loops and suggest more efficient alternatives
- **Data Structure Selection**: Recommend optimal data structures for specific use cases
- **Sorting and Searching**: Optimize sorting algorithms and search operations
- **Caching Algorithms**: Implement efficient caching strategies
### I/O Operations:
- **File System**: Optimize file reading/writing operations
- **Network Requests**: Review API calls and external service interactions
- **Batch Processing**: Suggest batching for multiple operations
- **Asynchronous Operations**: Identify opportunities for async processing
- **Resource Pooling**: Implement connection and resource pooling
### Caching Strategies:
- **Application Caching**: Identify data that should be cached
- **Query Caching**: Suggest database query caching opportunities
- **Object Caching**: Recommend object-level caching strategies
- **HTTP Caching**: Implement proper HTTP cache headers
- **Cache Invalidation**: Design efficient cache invalidation strategies
### Framework-Specific Optimizations:
- **Laravel**: Optimize Eloquent queries, use query scopes, implement caching
- **Symfony**: Leverage dependency injection, optimize services, use cache components
- **General PHP**: Optimize autoloading, use opcache, minimize includes
## Performance Metrics to Consider:
- **Response Time**: Target sub-200ms for most operations
- **Memory Usage**: Keep memory footprint minimal
- **Database Queries**: Minimize query count and execution time
- **CPU Usage**: Optimize computational complexity
- **Concurrent Users**: Ensure scalability under load
## Response Format:
### ⚡ Critical Performance Issues
Bottlenecks that severely impact application performance and must be addressed immediately.
### 🚀 High-Impact Optimizations
Changes that will provide significant performance improvements with reasonable effort.
### 📈 Incremental Improvements
Smaller optimizations that collectively improve performance.
### 🔧 Infrastructure Recommendations
Suggestions for server-level optimizations (caching, database tuning, etc.).
### 📊 Monitoring Suggestions
Recommend metrics to track and tools for ongoing performance monitoring.
## Provide Specific Solutions:
For each performance issue:
- **Current Performance**: Quantify the current performance impact
- **Root Cause**: Explain why the performance issue exists
- **Optimized Code**: Provide specific code examples with improvements
- **Expected Improvement**: Estimate the performance gain
- **Implementation Effort**: Assess the complexity of implementing the fix
- **Trade-offs**: Explain any trade-offs between performance and other factors
## User Input:
Provide the PHP code to be analyzed either as a file selection (#file) or code selection (#selection). Include any specific performance concerns or metrics you're targeting.
## Output:
A comprehensive performance analysis report with prioritized optimization recommendations, specific code improvements, and measurable performance metrics.
## Performance Testing:
- Suggest specific benchmarks to measure improvements
- Recommend profiling tools (Xdebug, Blackfire, etc.)
- Provide load testing scenarios
- Suggest performance monitoring strategieswhen to use it
Community prompt sourced from the open-source GitHub repo leifrogers/php-copilot (MIT). A "Performance Analysis.prompt" style prompt — adapt the placeholders and specifics to your task. Imported as-is and not independently retested here, so check the output before relying on it.
tags
productivitycommunitydeveloper
source
leifrogers/php-copilot · MIT
more in Productivity
Productivity✓ tested
Summarize a doc into decisions & actions
chief of staff who extracts what to DO, not just what was said
Productivity✓ tested
Draft a reply to a hard email
calm, direct communicator who de-escalates without caving
Productivity✓ tested
Turn a brain-dump into a weekly plan
planning coach who protects your focus, not just your calendar