用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/caarlos0/dotfiles --skill python-performance命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Review code, diffs, branches, commits, and pull requests for correctness, tests, simplicity, performance, and usability.
Debug cross-platform process, shell, sandbox, pipe, handle, startup, and shutdown behavior. Use for hangs, output loss, focus changes, lifecycle races, or platform-specific runtime failures.
Write deterministic tests that fail for real product defects. Use when adding tests, fixing flakes, or reviewing test coverage and reliability.
正在显示 SKILL.md
| name | python-performance |
| description | Profile and optimize Python CPU, memory, I/O, concurrency, and numerical performance. |
Name the metric first: wall time, CPU time, allocation count, retained heap, peak RSS, or I/O wait. Pin Python, dependencies, input, and environment; then change one profiled cause.
pyperf for repeatable benchmarks with calibration, worker processes,
metadata, and statistical comparison.timeit only for small fragments. It disables cyclic GC during timing
unless explicitly re-enabled, which can make allocation-heavy code look
unlike production.cProfile for call counts and cumulative development profiles; use a
sampling profiler such as py-spy for lower-overhead process observation.tracemalloc for Python-managed allocations. If RSS grows while its
traces remain stable, inspect native allocations or fragmentation with
Memray or an OS profiler.sys.getsizeof is shallow; it does not measure referenced objects.python -X importtime before changing startup imports.Choose from access patterns:
| Need | Prefer |
|---|---|
| Membership or deduplication | set or dict, not repeated list scans |
| Queue operations at both ends | collections.deque, not list.pop(0) |
| Priority queue | heapq |
| Search in maintained sorted data | bisect |
| Mutable binary accumulation | bytearray, then bytes(buffer) |
| Many string fragments | collect fragments and "".join(parts) |
These choices change semantics and memory. Do not replace a list when callers need indexing, slicing, or compact iteration.
Generators avoid eager materialization but add iteration overhead and cannot be reused. Built-ins and comprehensions often move work into optimized C loops, but they are not automatically faster for every workload.
lru_cache trades CPU for retained memory and invalidation. On an instance
method, cache keys retain self; avoid it when instances must be collected.
@dataclass(slots=True) or __slots__ can reduce memory for many instances but
affects dynamic attributes, inheritance, weak references, serialization, and
framework integration.
CPython uses reference counting plus cyclic GC. Distinguish:
High RSS alone is not a leak. Tune GC thresholds, call gc.freeze(), or change
allocators only after pause, allocation, or copy-on-write measurements identify
the collector or allocator as the cause. GC defaults differ by Python version
and free-threaded build.
asyncio is cooperative concurrency. Any blocking call or long CPU loop in a
coroutine stalls the event loop. Use bounded queues when producers can outrun
consumers, and preserve cancellation and shutdown.readinto() can reuse a
buffer in measured binary pipelines but adds ownership complexity.out=,
in-place operations, chunking, or fused kernels only after CPU and memory
profiles show the temporary matters.threadpoolctl or
environment settings.Use dis.dis(fn, adaptive=True) after warm-up as supporting evidence for a hot
loop. Do not redesign APIs to preserve one specialized opcode; specialization
rules change between versions. Re-measure after Python upgrades.
Use narrow allocation, output-size, startup, or memory guards when the toolchain and platform are pinned. Wall-time gates require dedicated hardware or enough margin to avoid flaking; keep shared-runner timing advisory. Never compare runs with different GC modes, profilers, hooks, or calibration.
code-review checks a completed diff. When invoked from code-review, do not
invoke it again.code-simplifier runs after the gain is proven.change-impact-auditor traces environment, serialization, imports, logging,
and concurrency changes.runtime-process-debugging owns subprocess, pipe, lifecycle, and shutdown
failures.Correctness overrides performance.