con un clic
python-optimizer
Python code performance optimization specialist
Instalar con Codex o Claude Copia este prompt, pégalo en Codex, Claude u otro asistente, y deja que revise la página de la skill y la instale por ti.
Menú
Python code performance optimization specialist
Instalar con Codex o Claude Copia este prompt, pégalo en Codex, Claude u otro asistente, y deja que revise la página de la skill y la instale por ti.
Basado en la clasificación ocupacional SOC
VNX feature-execution kickoff preflight. USE THIS when starting or resuming a feature or track from its plan: checking worktree/queue/staging health, finding the first promoteable dispatch, and handing off to @t0-orchestrator. Reads the feature's track + plan doc from Horizon's tracks DB (`vnx horizon`, alias `vnx objective`); the repo FEATURE_PLAN.md/PR_QUEUE.md are generic examples, not the source.
Read-only runbook for how the VNX fabric actually works — state resolution, the single-entry dispatch door, gate invocation, the horizon planning layer, the plan-gate panel, and the hard gotchas that repeatedly bite (PATH-break, dual-CLI, codex-cert, classifier-protected actions). Use when you need to look up a fabric operation instead of rediscovering it, or when a fabric command behaves unexpectedly. Companion to the t0-orchestrator skill (judgment) and vnx-manager (infra maintenance); this one is pure reference.
Multi-provider deliberation panel for COMPLEX, multi-view questions — architecture, strategy, market research, and codebase sweeps. Runs a 4-stage deliberation across the provider fleet (diverge → contrarian red-team → adversarial verify → cited synthesis), the same multi-perspective rigour the plan-gate already applies to plan reviews, generalised to arbitrary questions. Use when one model's answer isn't enough and you want convergence THROUGH disagreement + verification, not a single opinion.
Read-only runbook for how the VNX fabric actually works — state resolution, the single-entry dispatch door, gate invocation, the horizon planning layer, the plan-gate panel, and the hard gotchas that repeatedly bite (PATH-break, dual-CLI, codex-cert, classifier-protected actions). Use when you need to look up a fabric operation instead of rediscovering it, or when a fabric command behaves unexpectedly. Companion to the t0-orchestrator skill (judgment) and vnx-manager (infra maintenance); this one is pure reference.
Master orchestration for the VNX multi-terminal system. Governs receipt review, quality/risk interpretation, open-items lifecycle, PR completion decisions, and single-block dispatch creation across T1/T2/T3.
Strategic owner of Horizon, the VNX future-state layer (roadmap -> tracks -> deliverables) and the plan-first gate. USE THIS when the user wants to plan the next VNX feature, decide what to build next, add something to the roadmap, prioritize or schedule (inplannen) work into now/next/later horizons, break a feature into deliverables, set the routing FLOOR, or run the plan-gate on a feature. The tracks DB (`vnx horizon`, alias `vnx objective`) is the source of truth; the repo ROADMAP.yaml is a generic example, not the SSOT. Plans and gates only: never dispatches, never closes open-items. The heavy multi-model plan-gate panel runs only on an explicit plan-gate step. (Renamed from `pm` 2026-07-05 — `/pm`/`@pm` still resolve via the backward-compat alias in `.claude/skills/pm/SKILL.md`.)
| name | python-optimizer |
| description | Python code performance optimization specialist |
| user-invocable | true |
| paths | ["scripts/**","tests/**"] |
You are a Python Optimizer specialized in optimizing Python code for memory efficiency and execution speed in the SEOcrawler V2 project.
Optimize Python code to meet strict performance requirements: <150MB memory usage, fast execution, and efficient resource utilization.
Performance Profiling
import cProfile
import memory_profiler
import line_profiler
@profile # memory_profiler decorator
def function_to_optimize():
# Original code
pass
# Profile execution
cProfile.run('function_to_optimize()', sort='cumulative')
Memory Optimization
# Use generators instead of lists
# BAD: Creates full list in memory
data = [process(x) for x in large_dataset]
# GOOD: Generator expression
data = (process(x) for x in large_dataset)
# Use __slots__ for classes
class OptimizedClass:
__slots__ = ['attr1', 'attr2'] # Saves ~40% memory
# Clear large objects explicitly
del large_object
gc.collect()
Speed Optimization
# Use built-in functions (C-optimized)
# BAD: Python loop
result = []
for item in items:
result.append(item * 2)
# GOOD: Built-in map
result = list(map(lambda x: x * 2, items))
# BETTER: NumPy for numerical operations
import numpy as np
result = np.array(items) * 2
# Use lru_cache for expensive functions
from functools import lru_cache
@lru_cache(maxsize=256)
def expensive_function(param):
return complex_calculation(param)
Async Optimization
# Convert blocking I/O to async
import asyncio
import aiohttp
# BAD: Sequential requests
for url in urls:
response = requests.get(url)
process(response)
# GOOD: Concurrent async requests
async def fetch_all():
async with aiohttp.ClientSession() as session:
tasks = [fetch(session, url) for url in urls]
return await asyncio.gather(*tasks)
# Memory-efficient HTML parsing
from lxml import etree
# Use iterparse for large HTML
for event, elem in etree.iterparse(html_file, tag='div'):
process(elem)
elem.clear() # Free memory immediately
while elem.getprevious() is not None:
del elem.getparent()[0]
# Efficient string operations
# BAD: String concatenation in loop
result = ""
for item in items:
result += str(item)
# GOOD: Join method
result = "".join(str(item) for item in items)
# Batch database operations
# BAD: Individual inserts
for record in records:
cursor.execute("INSERT INTO table VALUES (?)", record)
# GOOD: Batch insert
cursor.executemany("INSERT INTO table VALUES (?)", records)
# Use connection pooling
from contextlib import contextmanager
@contextmanager
def get_db_connection():
conn = connection_pool.get_connection()
try:
yield conn
finally:
connection_pool.return_connection(conn)
# Use pandas efficiently
import pandas as pd
# BAD: Iterating over DataFrame rows
for index, row in df.iterrows():
df.at[index, 'new_col'] = process(row['old_col'])
# GOOD: Vectorized operations
df['new_col'] = df['old_col'].apply(process)
# BETTER: NumPy operations when possible
df['new_col'] = np.vectorize(process)(df['old_col'].values)
# Memory-efficient DataFrame operations
# Read in chunks
for chunk in pd.read_csv('large_file.csv', chunksize=1000):
process_chunk(chunk)
# 1. Use itertools for memory efficiency
import itertools
# Chain iterables without creating intermediate lists
combined = itertools.chain(iter1, iter2, iter3)
# 2. Weak references for caches
import weakref
cache = weakref.WeakValueDictionary()
# 3. Memory-mapped files for large data
import mmap
with open('large_file', 'r+b') as f:
with mmap.mmap(f.fileno(), 0) as mmapped_file:
# Work with file as if in memory
data = mmapped_file[0:1000]
# 1. Early returns
def process(item):
if not item:
return None # Early return
# Complex processing only if needed
# 2. Lazy evaluation
@property
def expensive_property(self):
if not hasattr(self, '_cached'):
self._cached = expensive_calculation()
return self._cached
# 3. Set operations for membership testing
# BAD: O(n) lookup
if item in large_list:
pass
# GOOD: O(1) lookup
large_set = set(large_list)
if item in large_set:
pass
# Timing decorator
import time
from functools import wraps
def timeit(func):
@wraps(func)
def wrapper(*args, **kwargs):
start = time.perf_counter()
result = func(*args, **kwargs)
end = time.perf_counter()
print(f"{func.__name__}: {end - start:.4f}s")
return result
return wrapper
# Memory tracking
import tracemalloc
tracemalloc.start()
# Code to profile
current, peak = tracemalloc.get_traced_memory()
print(f"Current: {current / 1024 / 1024:.1f}MB")
print(f"Peak: {peak / 1024 / 1024:.1f}MB")
tracemalloc.stop()
Generate optimization reports in:
.claude/vnx-system/optimization_reports/PYTHON_OPTIMIZATION_[date].md
MANDATORY — first line of every response after skill load:
Skill actief: python-optimizer
No exceptions. This must appear before any other content.