# Rust Performance And Layout

> Use for Rust performance work, allocation pressure, data layout, hot-path APIs, benchmarks, and when layout or copying choices affect runtime behaviour. Use when this capability is needed.

- Skill: `tomevault-io/rust-performance-and-layout` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/rust-performance-and-layout`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/rust-performance-and-layout/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/rust-performance-and-layout

---


# Rust Performance and Layout

Use this when performance matters enough to justify design pressure.

## Working stance

- Measure before changing shapes.
- Fix the largest hot-path cost, not the most obvious micro-optimization.
- Keep iterator pipelines lazy until you genuinely need a collection.
- Reuse allocations and tighten data movement before reaching for cleverness.
- Keep layout decisions explicit when they affect cache use or FFI.
- Prefer simple code unless profiling proves it is the bottleneck.

## Decision surface

| Pressure | First move |
| --- | --- |
| repeated allocation | reuse buffers, pre-size collections |
| large enum or struct footprint | inspect layout, box rare large fields |
| string and byte churn | borrow or use slices/bytes where lifetimes allow |
| clone-heavy hot path | revisit ownership and API boundaries |
| "faster" rewrite with no numbers | benchmark first |

## Red flags

- benchmarking starts after the rewrite,
- iterator chains collect into temporary `Vec`s only to be filtered or walked
  again,
- hot loops build strings with repeated `format!()` calls,
- index-based loops appear where iterators express the same walk clearly,
- tiny local wins complicate the API surface,
- hot-path code formats strings or allocates collections repeatedly,
- data layout changes happen without measuring access patterns,
- unsafe code is introduced before safe structural fixes are tried.

Read [allocation-and-reuse.md](references/allocation-and-reuse.md),
[data-layout.md](references/data-layout.md),
[benchmark-discipline.md](references/benchmark-discipline.md), and
[rigorous-benchmarking.md](references/rigorous-benchmarking.md) for the
common forks. The last covers paired benchmarking (Tango), deterministic
profiling (`iai-callgrind`), open-versus-closed load models, tail latency
and goodput.

---
> Source: [leynos/rust-skill](https://github.com/leynos/rust-skill) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-06-16 -->

