rust-memory-layout
Skill4 starsChanged 2 months agoApache-2.0View on GitHub
Investigate Rust allocations, copies, buffer retention, collection layout, and cache locality. Use for measured memory or data-access bottlenecks, not blanket clone removal.
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-buffer-performanceSkill
- 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-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
5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 9
Start with the ownership path and observed cost.
- Distinctive: line 19
Prefer moving existing ownership, writing into caller-owned buffers, reserving a justified capacity, or reusing scratch storage within a …
- Distinctive: line 21
Keep zero-copy boundaries honest.
- Very specific: line 29
Use safe slice/chunk APIs before unchecked indexing or representation casts.
- Distinctive: line 37
Read memory investigation notes for implementation-specific questions.
≈ “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
Rust Memory and Data Layout
Start with the ownership path and observed cost. Preserve the existing safety, API, and serialization contracts. Use $rust-performance for the overall experiment when available; this skill focuses on the memory mechanism.
Trace data through the operation
Map input ownership, parsing, intermediate values, queues/caches, output ownership, and destruction. Identify actual allocations and deep copies separately from shallow handles. Measure allocations per operation, bytes allocated, peak live memory, and retained memory under representative steady-state and burst load. RSS is useful but is not identical to live heap bytes or a leak.
Examine common and worst-case sizes and lifetimes. A small borrowed view or Bytes slice may retain a much larger owner. A buffer pool may lower allocation count while raising high-water memory. A change is not better merely because .clone() disappears or an allocation counter falls.
Choose the simplest effective representation
Prefer moving existing ownership, writing into caller-owned buffers, reserving a justified capacity, or reusing scratch storage within a bounded lifetime. Validate input lengths before reserving; attacker-controlled lengths are not safe capacity hints. Use checked arithmetic for byte counts, offsets, multiplication, and conversion across integer widths.
Keep zero-copy boundaries honest. Distinguish no payload copy from no allocation, no reference-count operation, and no later consumer copy. Convert to ownership deliberately when a result must outlive input or enter a background task. A small copy can reduce retention and simplify aliasing.
Consider contiguous layouts, compact indices, inline small values, batching, or structure-of-arrays only for the observed access pattern. Include object size, cache misses, initialization, deletion, and index maintenance in the comparison. Do not assume an inline collection is always cheaper: unused capacity can inflate every object. Prefer existing types and small local code over a dependency without a measured need.
Choose maps and hashers according to adversarial input, deterministic output requirements, and lookup workload. Do not trade away hash-flooding resistance casually. Stable output ordering should be explicit; it must not depend on incidental randomized iteration order.
Preserve safety and portability
Use safe slice/chunk APIs before unchecked indexing or representation casts. Never change repr, field layout, packed access, or byte interpretation merely to silence padding reports; Rust memory layout is not a wire format. Do not bypass a crate's forbid(unsafe_code) policy for a microbenchmark.
For long-lived caches and arenas, define the retention boundary and invalidation owner. Inspect stale IDs and generation checks after deletion or compaction. Avoid making every request retain an entire graph snapshot when a smaller result suffices.
Validate and return
Run behavioral tests and realistic burst/steady-state measurements. Check tiny inputs, large payloads, high concurrency, and repeated clear/reuse cycles. Compare latency and memory together. Report which copy/allocation was removed, the ownership lifetime before and after, measured costs, and any increased retained memory or complexity.
Read memory investigation notes for implementation-specific questions.
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.

