rust-performance

Master Rust performance - profiling, benchmarking, and optimization

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "rust-performance" with this command: npx skills add pluginagentmarketplace/custom-plugin-rust/pluginagentmarketplace-custom-plugin-rust-rust-performance

Rust Performance Skill

Master performance optimization: profiling, benchmarking, and zero-cost abstractions.

Quick Start

Benchmarking

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }

[[bench]]
name = "my_bench"
harness = false
use criterion::{criterion_group, criterion_main, Criterion, black_box};

fn benchmark(c: &mut Criterion) {
    c.bench_function("fib", |b| {
        b.iter(|| fibonacci(black_box(20)))
    });
}

criterion_group!(benches, benchmark);
criterion_main!(benches);

Profiling

cargo install flamegraph
cargo flamegraph --bin my-app

Optimization Patterns

Avoid Allocations

// ❌ Allocates each iteration
for s in strings {
    result = result + &s;
}

// ✅ Pre-allocate
let mut result = String::with_capacity(total_len);
for s in strings {
    result.push_str(&s);
}

Use Iterators

// ❌ Intermediate collection
let v: Vec<_> = data.iter().map(|x| x * 2).collect();
let sum: i32 = v.iter().sum();

// ✅ Lazy chain
let sum: i32 = data.iter().map(|x| x * 2).sum();

Cow for Optional Clone

use std::borrow::Cow;

fn process(input: &str) -> Cow<str> {
    if input.contains("bad") {
        Cow::Owned(input.replace("bad", "good"))
    } else {
        Cow::Borrowed(input)
    }
}

Release Profile

[profile.release]
lto = true
codegen-units = 1
opt-level = 3

Troubleshooting

ProblemSolution
Slow debugUse --release
Memory spikesUse streaming
Cache missesImprove data layout

Resources

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

error-handling

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

rust-wasm

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

rust-docker

No summary provided by upstream source.

Repository SourceNeeds Review