python-performance-optimization
Optimize Python code performance and profiling
こちらからも入手できます: wshobson,ActiveInferenceInstitute
Slow Python code wastes resources and frustrates users. This skill provides systematic profiling and optimization techniques to identify bottlenecks and improve performance.
スキルZIPをダウンロード
Claudeでアップロード
設定 → 機能 → スキル → スキルをアップロードへ移動
オンにして利用開始
テストする
「python-performance-optimization」を使用しています。 Profile a function that processes a large list
期待される結果:
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.
「python-performance-optimization」を使用しています。 Analyze memory usage pattern
期待される結果:
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.
セキュリティ監査
安全Static 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.
品質スコア
作れるもの
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.
これらのプロンプトを試す
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.
ベストプラクティス
- 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
回避
- 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