AGENT SKILL

python-performance-optimization

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.

License 许可
MIT
最近更新
2026-11-12
Stars
★ 1
Forks
0

01 前言 Front Matter

name
python-performance-optimization
metadata
{ "skill-graph-id": "plugin/10x-swe/python-performance-optimization", "skill-graph-uses": "", "skill-graph-used-by": "" }
description
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.

02 资源文件 1

03 SKILL.md 正文

Python Performance Optimization

Use this skill to find and reduce measured Python bottlenecks. Preserve behavior and compare representative workloads before claiming improvement.

Workflow

  1. Define the performance problem and target: latency distribution, throughput, peak memory, CPU use, or I/O wait. Record runtime, hardware, input size, and workload characteristics.
  2. Establish a repeatable baseline. Separate initialization, steady-state work, and cache effects. Use timeit for small operations and appropriate end-to-end measurements for user-visible performance.
  3. Locate the bottleneck: cProfile for call costs, line profiling for a confirmed hot function, tracemalloc for allocation changes, and sampling tools for running processes. Inspect production only within authorized scope.
  4. Improve algorithms and data layout before micro-optimizing. Consider indexes and batching for databases, streaming for large inputs, bounded caches for repeated work, and vectorization for suitable numeric workloads.
  5. Choose concurrency for the bottleneck. Async helps overlapping I/O; processes can parallelize CPU work but add serialization and startup costs. Threads benefit blocking I/O and workloads that release the GIL.
  6. Change one hypothesis at a time. Re-run correctness checks and identical benchmarks. Report absolute results and variance, not only a speedup ratio.
  7. Check tradeoffs: memory, cache invalidation, contention, startup time, transaction semantics, and maintainability. Keep the simpler implementation when the gain is not material.

Reference routing

Open the relevant section of detailed patterns:

  • Profiling Tools: CPU, line, memory, and sampling examples.
  • Optimization Patterns: collections, generators, strings, lookups, and call overhead.
  • Advanced Optimization: NumPy, caching, slots, processes, and async I/O.
  • Database Optimization and Memory Optimization: batching, query plans, allocation snapshots, streaming, and weak caches.
  • Benchmarking Tools: timing and pytest-benchmark examples.

Preserved examples are experiments, not performance guarantees. map is not always faster than a comprehension; NumPy includes allocation costs and fixed-width arithmetic semantics. sys.getsizeof() does not measure referenced objects or total retained memory. The leak sketch drops its local references on return and does not demonstrate a retained leak. Validate these claims against the actual workload.

Acceptance

Provide the baseline, final measurement, relevant environment, correctness results, and remaining limits. Do not introduce caches, dependencies, schema changes, or production profiling permissions merely because they appear in an example.

04 同仓库更多 Skills

cercova-studios
cercova-studios/10x-swe

turnstile-spin

Set up Cloudflare Turnstile end-to-end in a project. Scan the codebase, create the widget via the Cloudflare API, embed it where user requests need bot verification (form submissions, SPA actions, API endpoints, download links, comment or vote submissions, etc.), wire canonical server-side siteverify in the customer's existing backend, validate, and persist the skill. Load this when a user asks to add Turnstile, set up CAPTCHA, protect a form or endpoint from bots, or fix a Turnstile integration. Uses Cloudflare's documented Turnstile contract.

后端与接口
★ 1
cercova-studios
cercova-studios/10x-swe

frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

设计师前端开发视觉设计
★ 1
cercova-studios
cercova-studios/10x-swe

source-insights

Prepare inspected source evidence, preserve exact citations, and publish reviewed insights into an explicit local library.

★ 1
cercova-studios
cercova-studios/10x-swe

skill-graph

Discover skills and workflows through independent lexical search, relationship paths and a terminal graph.

Skill与智能体开发
★ 1
cercova-studios
cercova-studios/10x-swe

session-search

Recall public session turns with exact provenance, bounded excerpts and independent piped exports.

★ 1
cercova-studios
cercova-studios/10x-swe

newsletter

Produce a private local AI newsletter from bounded public research, with cited deep dives, HTML/Markdown output, Dagu scheduling and seven-day retention.

邮件与沟通资料检索与研究
★ 1