python-performance-optimization
できること
このツールは、Pythonコードの中で遅い部分を見つけて改善するのに役立ちます。プログラムがどこで最も多くの時間やメモリを使っているかを分析し、より速く効率的にするための方法を提案します。
使う場面
- ✓Pythonプログラムの実行に時間がかかりすぎているとき。
- ✓プログラムがメモリを使いすぎていると感じるとき。
- ✓公開する前に、コードをより速くしたいとき。
スキルのリンク
https://github.com/wshobson/agents/blob/main/plugins/python-development/skills/python-performance-optimization/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“Pythonコードの動きがとても遅いのですが、原因を見つけるのを手伝ってもらえますか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
このツールはコードを分析して、実行に最も時間がかかる部分や、最もメモリを消費している部分を調べます。そのうえで、より効率的なデータ構造を使う、より速いアルゴリズムを使うなどの変更を提案します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Python Performance Optimization
Comprehensive guide to profiling, analyzing, and optimizing Python code for better performance, including CPU profiling, memory optimization, and implementation best practices.
When to Use This Skill
- Identifying performance bottlenecks in Python applications
- Reducing application latency and response times
- Optimizing CPU-intensive operations
- Reducing memory consumption and memory leaks
- Improving database query performance
- Optimizing I/O operations
- Speeding up data processing pipelines
- Implementing high-performance algorithms
- Profiling production applications
Core Concepts
1. Profiling Types
- CPU Profiling: Identify time-consuming functions
- Memory Profiling: Track memory allocation and leaks
- Line Profiling: Profile at line-by-line granularity
- Call Graph: Visualize function call relationships
2. Performance Metrics
- Execution Time: How long operations take
- Memory Usage: Peak and average memory consumption
- CPU Utilization: Processor usage patterns
- I/O Wait: Time spent on I/O operations
3. Optimization Strategies
- Algorithmic: Better algorithms and data structures
- Implementation: More efficient code patterns
- Parallelization: Multi-threading/processing
- Caching: Avoid redundant computation
- Native Extensions: C/Rust for critical paths
Quick Start
Basic Timing
import time
def measure_time():
"""Simple timing measurement."""
start = time.time()
# Your code here
result = sum(range(1000000))
elapsed = time.time() - start
print(f"Execution time: {elapsed:.4f} seconds")
return result
# Better: use timeit for accurate measurements
import timeit
execution_time = timeit.timeit(
"sum(range(1000000))",
number=100
)
print(f"Average time: {execution_time/100:.6f} seconds")
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices
- Profile before optimizing - Measure to find real bottlenecks
- Focus on hot paths - Optimize code that runs most frequently
- Use appropriate data structures - Dict for lookups, set for membership
- Avoid premature optimization - Clarity first, then optimize
- Use built-in functions - They're implemented in C
- Cache expensive computations - Use lru_cache
- Batch I/O operations - Reduce system calls
- Use generators for large datasets
- Consider NumPy for numerical operations
- Profile production code - Use py-spy for live systems
Common Pitfalls
- Optimizing without profiling
- Using global variables unnecessarily
- Not using appropriate data structures
- Creating unnecessary copies of data
- Not using connection pooling for databases
- Ignoring algorithmic complexity
- Over-optimizing rare code paths
- Not considering memory usage
よくある質問
「プロファイリング」とは何ですか?
プログラムの実行中の様子をスナップショットのように記録し、どこで時間や資源を使っているかを調べることです。
なぜコードを最適化するのですか?
プログラムをより速く動かし、メモリの使用量を減らし、効率を高めるためです。資源を節約し、利用者の体験も向上します。
このツールを使うには、プログラミングの専門家である必要がありますか?
いいえ。このツールは、問題の特定と解決策の提案に重点を置いているため、専門家でなくても使えるように設計されています。
詳細
作者による元の説明
Profile and optimize Python code using cProfile, memory profilers, and performance best practices. Use when debugging slow Python code, optimizing bottlenecks, or improving application performance.
repo: wshobson/agents
人気
- GitHubのスター
- 41k
- ランキング
- #6764
- ライセンス
- MIT
- 更新日
- 2026/10/15
コメント
- …
このリポジトリの他のスキル
screen-reader-testing
41kエージェントにスクリーンリーダーを使ってWebサイトをテストさせ、アクセシビリティを確認します。
wcag-audit-patterns
41kエージェントがWebサイトのアクセシビリティを監査し、WCAGガイドラインに沿って問題を修正できるようにします。
multi-reviewer-patterns
41kエージェントが複数のコードレビューを並行して調整できるようにします。指摘事項の重複を排除し、レポートにまとめます。
parallel-debugging
41kエージェントが並行調査と根本原因分析を使って、複雑な問題をデバッグできるようにします。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。