pyo3-buffer-performance
Skill4 starsChanged 2 months agoApache-2.0View on GitHub
Use for measured Python/Rust boundary overhead, batching, Bytes/memoryview/NumPy exchange, zero-copy ownership, and native thread oversubscription. Not an instruction to replace correct copies with unsafe views.
In this repository81 other files it gives its agents.
- agent-cli-designSkill
- agent-tool-boundariesSkill
- behavior-first-implementationSkill
- bounded-prototypeSkill
- bounded-pr-sliceSkill
- building-fdd-validationSkill
- context-efficiencySkill
- cross-language-contractsSkill
- cross-platform-agent-instructionsSkill
- design-interviewSkill
- diagnosis-loopSkill
- domain-languageSkill
- edge-cloud-syncSkill
- handoff-continuitySkill
- immutable-pr-reviewSkill
- memory-context-hygieneSkill
- module-designSkill
- orchestrateSkill
- owner-decision-gateSkill
- parallel-portfolioSkill
- pr-gate-loopSkill
- pyo3-async-lifecycleSkill
- pyo3-free-threadingSkill
- pyo3-ownership-errorsSkill
- pyo3-wheel-releaseSkill
- python-api-typingSkill
- python-async-concurrencySkill
- python-ci-releaseSkill
- python-data-boundariesSkill
- python-packaging-environmentsSkill
- python-performanceSkill
- python-pytestSkill
- python-reviewSkill
- python-test-designSkill
- python-threading-workersSkill
- python-workflowSkill
- react-components-stateSkill
- react-performanceSkill
- repository-groundingSkill
- rust-api-designSkill
- rust-async-concurrencySkill
- rust-build-diagnosticsSkill
- rust-ci-releaseSkill
- rust-memory-layoutSkill
- rust-nextestSkill
- rust-numerics-simdSkill
- rust-performanceSkill
- rust-protocol-codecsSkill
- rust-python-bindingsSkill
- rust-reviewSkill
- rust-storage-durabilitySkill
- rust-test-designSkill
- rust-unsafe-ffiSkill
- rust-workflowSkill
- rust-workspace-dependenciesSkill
- shadcn-react-componentsSkill
- shadcn-svelte-componentsSkill
- simplify-existing-codeSkill
- source-verificationSkill
- svelte-components-runesSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
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
- Distinctive: line 25
Avoid multiplying Python executors, Tokio workers, Rayon threads, and BLAS/OpenMP pools.
- Distinctive: line 27
Leave PyO3 reference-pool disabling, raw-pointer shortcuts, unchecked conversion, and specialized CPU flags out unless explicit evidence …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
PyO3 Buffers and Performance
Identify a real workload and measure the Python-visible operation before changing its representation. Separate Python call dispatch, argument extraction, allocation/copies, native kernel work, result construction, and I/O. A Rust-only microbenchmark does not measure the Python boundary.
Choose the cheapest safe crossing
First consider fewer calls, batching, moving invariant conversion out of loops, reusing owned native objects, and returning a compact result. Avoid adding a framework or dependency for a small unmeasured gain. Preserve latency, cancellation granularity, memory bounds, units, precision, and public result semantics while batching.
For each buffer, record exporter/owner lifetime, dtype/item size, alignment, byte order, shape/strides, contiguity, writeability, overlapping views, and possible concurrent mutation. Validate dimensions and lengths with overflow-safe arithmetic before indexing or allocation. Do not reinterpret arbitrary bytes as typed aligned Rust slices or treat object-dtype arrays as plain numeric memory.
A read-only view is not proof that the backing allocation is immutable. rust-numpy borrow guards constrain cooperating Rust borrows; they do not synchronize arbitrary Python/C/Fortran mutation. Keeping an owner alive prevents deallocation but does not prevent resize or mutation through another alias. Detaching over externally mutable storage requires a valid exclusion/lifetime argument. When that cannot be established, make a bounded owned copy before detached work. Do not manufacture a runtime race to test known unsafe aliasing inside the main test process.
Use supported ownership-transfer/conversion APIs for outputs. An exposed view must keep storage alive after the temporary producer or input object is deleted. Remember that a tiny view may retain a large native allocation. Shared buffers, native caches, and reference cycles can dominate memory even when Python allocation tracing looks small.
Measure fairly
Compare equivalent interpreter/build/GIL modes and release-built native artifacts with identical input distributions. Measure small and large payloads, contiguous and strided inputs, aligned/misaligned or rejected inputs, and conversion-inclusive end-to-end performance. Record retained/process memory as well as allocation counts when relevant. tracemalloc alone does not account for arbitrary Rust/native allocations.
Avoid multiplying Python executors, Tokio workers, Rayon threads, and BLAS/OpenMP pools. Establish a whole-process concurrency budget before increasing any one pool. Do not change process-wide threading knobs invisibly or benchmark while other agents build.
Leave PyO3 reference-pool disabling, raw-pointer shortcuts, unchecked conversion, and specialized CPU flags out unless explicit evidence and safety review justify them. Some such options turn off-thread reference destruction into process aborts rather than a harmless speed tradeoff.
Report the boundary bottleneck, ownership/synchronization argument, measured change and variance, numerical/behavioral checks, and any workload regression.
Read buffer decisions.
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
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.

