performance

Guidance for improving the performance of Rust programs, with emphasis on measuring problems before changing code. Rust is a programming language, and profiling shows where a program spends time or memory.

In plain words
What is it for?
Choosing optimizations such as better algorithms, SIMD processing, compile-time techniques, allocation strategies, data structures, caching, buffering, asynchronous input/output, batching, and parallel processing.
Why use it?
It helps developers focus on the actual bottleneck instead of making untested optimizations. It covers CPU, memory, input/output, and concurrency issues.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/tyrchen/cursor-rust-rules/performance
Clone the repo
git clone --depth 1 https://github.com/tyrchen/cursor-rust-rules

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 4,168 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.04168
Opus 5 $0.00000 $0.02084
Sonnet 5 $0.00000 $0.00834
Haiku 4.5 $0.00000 $0.00417

Measured 2d ago against content hash c7110a0c389b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

performance scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/rust/core/performance.mdc · 639 lines

How it starts

The opening of the file, as written. The whole thing — 639 lines — stays where its author put it; the contents beside it link to each section on GitHub.

⚡ RUST PERFORMANCE OPTIMIZATION

TL;DR: Performance optimization strategies for Rust applications, focusing on zero-cost abstractions, memory management, and profiling-driven optimization.

🔍 PERFORMANCE OPTIMIZATION STRATEGY

graph TD
    Start["Performance Issue"] --> Measure["Profile & Measure"]

    Measure --> Bottleneck{"Bottleneck<br>Type?"}

    Bottleneck -->|CPU| CPUOpt["CPU Optimization"]
    Bottleneck -->|Memory| MemOpt["Memory Optimization"]
    Bottleneck -->|I/O| IOOpt["I/O Optimization"]
    Bottleneck -->|Concurrency| ConcOpt["Concurrency Optimization"]

    CPUOpt --> SIMD["SIMD Vectorization"]
    CPUOpt --> Algorithms["Algorithm Optimization"]
    CPUOpt --> CompileTime["Compile-Time Optimization"]

    MemOpt --> Allocation["Allocation Strategy"]
    MemOpt --> DataStructure["Data Structure Choice"]
    MemOpt --> Caching["Caching Patterns"]

    IOOpt --> Buffering["Buffering Strategy"]
    IOOpt --> AsyncIO["Async I/O Patterns"]
    IOOpt --> Batching["Request Batching"]

    ConcOpt --> Parallelism["Parallel Processing"]
    ConcOpt --> Channels["Channel Optimization"]
    ConcOpt --> LockFree["Lock-Free Structures"]

    SIMD --> Verify["Benchmark & Verify"]
    Algorithms --> Verify
    CompileTime --> Verify
    Allocation --> Verify
    DataStructure --> Verify
    Caching --> Verify
    Buffering --> Verify
    AsyncIO --> Verify
    Batching --> Verify
    Parallelism --> Verify
    Channels --> Verify
    LockFree --> Verify

    style Start fill:#4da6ff,stroke:#0066cc,color:white
    style Measure fill:#ffa64d,stroke:#cc7a30,color:white
    style CPUOpt fill:#4dbb5f,stroke:#36873f,color:white
    style MemOpt fill:#d94dbb,stroke:#a3378a,color:white

🎯 PERFORMANCE PRINCIPLES

Measure First, Optimize Second

// ✅ Always profile before optimizing
use std::time::Instant;

#[cfg(feature = "profiling")]
macro_rules! time_it {
    ($name:expr, $block:block) => {{
        let start = Instant::now();
        let result = $block;
        let duration = start.elapsed();
        tracing::info!("{} took {:?}", $name, duration);
        result
    }};
}

#[cfg(not(feature = "profiling"))]
macro_rules! time_it {
    ($name:expr, $block:block) => {
        $block
    };
}

// Usage
fn process_data(data: &[u8]) -> Vec<u8> {
    time_it!("process_data", {
        // Expensive computation here
        data.iter().map(|&b| b.wrapping_mul(2)).collect()
    })
}

Read the full file on GitHub · 639 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 639 lines · 0 tokens per session scan A c7110a0c389b

Subscribe to this mod's changes

performance is a cursor rule published in the GitHub repository tyrchen/cursor-rust-rules (27 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 4,168 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.