agentleFS
jscott3201jscott3201/yet-more-skills/skills/python-performance/SKILL.md

python-performance

Skill4 starsChanged 2 months agoApache-2.0View on GitHub

Profile, benchmark, or optimize Python CPU, latency, throughput, allocations, startup, or native-call overhead. Requires a representative workload; not a blanket rewrite into Rust.

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Remove repeated work and unnecessary protocol crossings first.

    line 21
  2. Distinctive:

    Run correctness tests before and after.

    line 27
  3. Distinctive:

    Read measurement notes for the boundary-specific questions.

    line 29

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Python Performance Engineering

Define the user-visible workload and correctness contract first. Identify whether the bottleneck is Python execution, object conversion, native compute, I/O, queuing, startup, or memory retention. Reuse an existing benchmark before adding another framework.

Establish a comparable baseline

Record the interpreter/build variant, GIL state after imports, extension build mode, relevant dependencies, input size, concurrency, and warm/cold conditions. Compare on the same native host without other benchmark or compilation jobs. Do not compare a debug extension to a release extension and attribute the difference to a code change.

Use a profiler to locate cost, then measure without profiling overhead. Standard-library cProfile and tracemalloc can answer Python questions, but Python allocation tracing does not automatically account for Rust Vec/Arc/allocator memory. Use native profiling or process-level measurements when the cost crosses that boundary, and distinguish live objects, allocator retention, mapped memory, and RSS.

Prefer a representative end-to-end case plus a focused microbenchmark. Use pyperf when already available or justified for repeated measurements; retain raw output and inspect instability. A single fastest timing, or an average with failures omitted, is not evidence. Measure completed operations and include error rate, payload shape, queue depth, and tail latency where relevant. Do not run privileged system tuning without explicit authorization.

Optimize in a useful order

Remove repeated work and unnecessary protocol crossings first. Consider batching, parsing once, fewer intermediate objects, better algorithms, bounded caching, and reusing connections. Check retained memory and latency tradeoffs: streaming can defer errors, batching can delay small requests, and caching can serve stale data.

At a Rust boundary measure Python conversion, native computation, and result construction separately. Replacing many small calls with one batch may matter more than a faster kernel. Avoid unsafe zero-copy, unconditional detachment, wholesale vectorization, new allocators, or a Rust rewrite without measured need.

For free-threading, measure both single-call overhead and realistic parallel scaling. Bound Python workers, Rust/Tokio/Rayon workers, and any numerical-library pools as one CPU budget. Independent processes or fewer threads may outperform nested parallelism; measure rather than prescribe.

Run correctness tests before and after. Report baseline/candidate measurements, variance, relevant regressions, and one of keep, reject, or inconclusive. Microbenchmark improvement is not a product-wide speedup.

Read measurement notes for the boundary-specific questions.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.