ソース情報
- リポジトリ
- dlt-hub/dlt
- ソースの最終更新活動
- 2026年2月18日 10:43
- 検出された SKILL.md の言語
- 英語
- スター
- 5,747
- フォーク
- 587
インストール方法
デフォルトでは、最初にソースを確認する Prompt が選択されています。直接コマンドに切り替えるか、ローカルコピーをダウンロードすることもできます。
ソースファイルを確認
インストールを決める前に、SKILL.md と SkillsMP に表示されている付属ファイルをお読みください。
メニュー
デフォルトでは、最初にソースを確認する Prompt が選択されています。直接コマンドに切り替えるか、ローカルコピーをダウンロードすることもできます。
インストールを決める前に、SKILL.md と SkillsMP に表示されている付属ファイルをお読みください。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
直接コマンドでは確認用 Prompt が省略されます。実行前にソースを確認してください。
npx skills add https://github.com/dlt-hub/dlt --skill optimize-codeコマンドは1行のまま表示されます。コピー前に横へスクロールして全体を確認してください。
ローカルで確認しますか?SkillsMP が現在取得できるファイルをダウンロードできます。
Create or reuse a git worktree for a pull request or branch so reviews and work happen in isolation
Triage, plan, and implement a fix or feature for a GitHub issue end-to-end
Create a git worktree with a new branch for implementing a fix or feature for a GitHub issue
SOC 職業分類に基づく
SKILL.md を表示中
| name | optimize-code |
| description | Analyze and optimize Python code performance in critical paths |
| argument-hint | <file-path-or-description> [-- <critical-path-hints>] |
You are a Python performance optimization expert. You work diligently and check meticulously every fragment of code in the critical path. You never assume - you trace actual execution paths, verify with evidence, and question defensive patterns that may have become unnecessary.
ALWAYS benchmark everything. Use timeit oneliners for quick validation, write dedicated benchmarks for optimization variants, and as the final step, benchmark optimized code against the baseline (devel branch).
Parse $ARGUMENTS to extract:
-- is the target: file path, function name, or description of code to optimize-- is critical path hints: which code paths matter most, what to ignoreSKIP if optimizing a single (or 1-2 ) functions where critical path is clear, otherwise INTERROGATE the user to understand the hot path before making any changes.
If $ARGUMENTS contains a file path, read it. Otherwise, ask the user:
Ask about the 90% case to focus optimization effort:
Follow the code from entry point through each function call:
entry_point() → helper_a() → helper_b() → actual_work()
Read each function in the chain. Identify the innermost loop where per-item work happens.
Before any optimization, create a benchmark for the current state:
import timeit
# Quick validation
python -c "import timeit; print(timeit.timeit('target_function()', setup='...', number=1000))"
Look for these patterns in the critical path:
dict(x) or list(x) when reference would sufficeself.method in loop vs method = self.method before loopx is y faster than x == y when applicable__slots__ for hot objectsObjects created frequently in hot paths benefit from __slots__:
__dict__)# Bad: regular class, dict-based attributes
class Row:
def __init__(self, table, data):
self.table = table
self.data = data
# Good: slotted class
class Row:
__slots__ = ['table', 'data']
def __init__(self, table, data):
self.table = table
self.data = data
Inner functions (closures) defined inside loops or hot functions are recreated on every call. This can be a major performance hit:
# Bad: inner function recreated per call
def process(items):
def transform(x): # created every time process() is called
return x * 2
return [transform(i) for i in items]
# Good: module-level or method
def _transform(x):
return x * 2
def process(items):
return [_transform(i) for i in items]
# Good: inline if simple
def process(items):
return [x * 2 for x in items]
Signs to look for:
def inside another defRecursive functions have overhead per call (stack frame, argument passing) and risk stack overflow on deep structures. Convert to stack-based iteration:
# Bad: recursive traversal
def flatten(obj, path=""):
if isinstance(obj, dict):
for k, v in obj.items():
yield from flatten(v, f"{path}.{k}") # recursive call
else:
yield path, obj
# Good: stack-based iteration
def flatten(obj):
stack = [(obj, "")]
while stack:
current, path = stack.pop()
if isinstance(current, dict):
for k, v in current.items():
stack.append((v, f"{path}.{k}"))
else:
yield path, current
Benefits:
WARN USER:
Caches (lru_cache, manual dicts, memoization) can hurt performance if:
Benchmark caches even if they already exist - they may have been added speculatively:
# Does this cache actually help? Benchmark with and without!
@lru_cache(maxsize=128)
def get_column_type(col_name):
return self.schema.columns[col_name]["data_type"]
# Compare:
# 1. With cache (current)
# 2. Without cache (direct lookup)
# 3. Different cache size
Before and after each micro-optimization:
python -c "import timeit; d={'a':1,'b':2}; print('copy:', timeit.timeit('dict(d)', globals={'d':d}, number=1000000))"
python -c "import timeit; d={'a':1,'b':2}; print('ref:', timeit.timeit('x=d', globals={'d':d}, number=1000000))"
For optimization variants, create benchmark scripts in experiments/ folder:
"""Benchmark: optimization variant comparison"""
import timeit
def variant_original(): ...
def variant_optimized(): ...
print("original:", timeit.timeit(variant_original, number=10000))
print("optimized:", timeit.timeit(variant_optimized, number=10000))
Run benchmarks in separate processes with pauses:
python experiments/bench.py devel_case
sleep 10
python experiments/bench.py optimized_case
Run each benchmark 3+ times to verify stability:
for i in 1 2 3; do
echo "=== Run $i ==="
python experiments/bench.py case_name
sleep 5
done
Variance over 10-15% suggests external factors (thermal throttling, system load).
Use real test data from tests/normalize/cases/:
| File | Size | Use Case |
|---|---|---|
ethereum.blocks.*.json + schemas/ethereum.schema.json | 2MB | Deep nesting, warm/cold path normalizer |
github.events.*.json | 1.7MB | Dynamic table routing, many event types |
github.issues.*.json | 526KB | REST API, moderate nesting |
Load with from dlt.common.json import json. For flat rows with ISO timestamps, use mimesis (in dev deps) to generate synthetic DB data.
As the last step, compare against baseline branch:
# On devel branch (main repo)
cd /path/to/main && python experiments/bench.py case_name
sleep 10
# On optimized branch (worktree)
cd /path/to/worktree && python experiments/bench.py case_name
Report: devel_time / optimized_time = X.XXx speedup
One optimization at a time. Benchmark after each change.
make test-commonAdd comments explaining why optimization is safe:
# columns dict is never mutated after get_table_columns() returns,
# so we can store reference instead of copying
self._current_columns = columns
Produce a summary:
## Optimization Summary
### Changes Made
1. Replaced dict copy with identity check (buffered.py:100)
2. Inlined count_rows_in_items for common case (buffered.py:102)
### Benchmark Results
| Case | Devel | Optimized | Speedup |
|------|-------|-----------|---------|
| flat_100 | 10.4s | 2.2s | 4.76x |
| nested_20 | 4.9s | 2.0s | 2.47x |
### Assumptions
- columns dict is immutable after creation
- 90% of items are plain dicts, not arrow/pandas