python-performance-optimization
Optimize Python code performance and profiling
Ăgalement disponible depuis: wshobson,ActiveInferenceInstitute
Slow Python code wastes resources and frustrates users. This skill provides systematic profiling and optimization techniques to identify bottlenecks and improve performance.
Télécharger le ZIP du skill
Importer dans Claude
Allez dans ParamĂštres â CapacitĂ©s â Skills â Importer un skill
Activez et commencez Ă utiliser
Tester
Utilisation de "python-performance-optimization". Profile a function that processes a large list
Résultat attendu:
Timing report showing process_data() consumed 2.3s (85% of total time), with 90% spent in nested loops. Recommendation: Replace O(nÂČ) algorithm with dictionary lookup for O(n) performance.
Utilisation de "python-performance-optimization". Analyze memory usage pattern
Résultat attendu:
Memory profile shows 500MB allocation in data_cache dictionary that grows unbounded. Recommendation: Implement LRU cache with maxsize parameter or use WeakValueDictionary for automatic cleanup.
Audit de sécurité
SûrStatic analysis flagged 68 patterns but all are false positives. The backtick detections are markdown code formatting, not shell execution. Network and URL findings are educational examples using test endpoints. SQLite references are documentation examples. System reconnaissance patterns are legitimate profiling tool demonstrations. This is a documentation-only skill with no executable code or security risks.
Score de qualité
Ce que vous pouvez construire
Debug slow API endpoints
Profile a web application to identify slow database queries and optimize response times.
Optimize data processing pipelines
Analyze memory usage and execution time of ETL workflows to reduce resource consumption.
Improve algorithm efficiency
Profile computational code to identify inefficient patterns and apply appropriate optimizations.
Essayez ces prompts
Help me profile this Python function to identify performance bottlenecks. Here is my code: [paste code]. Show me how to use cProfile to measure execution time and find slow functions.
My Python application uses increasing memory over time. Help me use memory_profiler and tracemalloc to identify memory leaks in this code: [paste code]. Explain what the output means.
I have profiled my code and found these bottlenecks: [paste profiling output]. Recommend specific optimization techniques and show before/after code examples for each suggestion.
Guide me through setting up py-spy to profile a running Python production service without stopping it. Explain how to generate flame graphs and interpret the results to find hot paths.
Bonnes pratiques
- Always profile before optimizing to identify actual bottlenecks, not assumed ones
- Use appropriate data structures: dictionaries for lookups, sets for membership tests, generators for large sequences
- Cache expensive computations with functools.lru_cache and batch I/O operations to reduce system call overhead
Ăviter
- Optimizing code without profiling data leads to wasted effort on non-bottlenecks
- String concatenation in loops using + operator instead of join() causes quadratic time complexity
- Loading entire files or datasets into memory when iterator-based processing would suffice