Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
zhanghandong avatar

M10 Performance

  • 911 installs
  • 1.3k repo stars
  • Updated May 24, 2026
  • zhanghandong/rust-skills

This is a copy of m10-performance by actionbook - installs and ranking accrue to the original listing.

m10-performance is a Rust skill that guides developers through CPU and memory profiling, Criterion benchmarking, and cache analysis to optimize speed and memory before shipping.

About

m10-performance is a Rust performance optimization guide from zhanghandong/rust-skills that teaches a profiling-first workflow before rewriting code. The skill documents concrete commands for cargo flamegraph CPU traces, cargo-instruments on macOS, heaptrack on Linux, cargo bench with Criterion, and valgrind --tool=cachegrind for cache behavior. It includes Criterion benchmark scaffolding with criterion_group and criterion_main so developers can compare parse_v1 versus parse_v2 implementations on repeated inputs. Developers reach for m10-performance when a Rust binary or library is functionally correct but too slow, memory-heavy, or cache-unfriendly, and they need a repeatable measurement loop instead of guessing at optimizations.

  • Profiling-first workflow using flamegraph, heaptrack, cachegrind and cargo bench
  • Criterion benchmark templates with multiple implementation comparisons
  • 9 common Rust performance patterns including Cow for zero-cost abstractions
  • Allocation reuse techniques that eliminate repeated Vec and String creation
  • Hard-gate: always profile before optimizing to avoid premature tuning

M10 Performance by the numbers

  • 911 all-time installs (skills.sh)
  • +6 installs in the week ending Jul 28, 2026 (Skillselion tracking)
  • Security screen: HIGH risk (skills.sh audit)
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
npx skills add https://github.com/zhanghandong/rust-skills --skill m10-performance

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs911
repo stars1.3k
Security audit2 / 3 scanners passed
Last updatedMay 24, 2026
Repositoryzhanghandong/rust-skills

How do you profile and benchmark Rust code before release?

Systematically profile, benchmark, and optimize Rust code for speed and memory efficiency before shipping.

Who is it for?

Rust developers shipping performance-sensitive binaries or libraries who need systematic profiling before rewriting algorithms or data structures.

Skip if: Teams still defining Rust architecture or correctness requirements who have not yet established baseline functionality tests.

When should I use this skill?

A Rust service is too slow, memory-heavy, or cache-unfriendly and the developer mentions flamegraph, Criterion, valgrind, or pre-ship optimization.

What you get

Flamegraph SVGs, Criterion benchmark reports, heap profiles, cachegrind output, and a prioritized list of Rust hot-path fixes.

  • Criterion benchmark suites
  • flamegraph profiles
  • optimization change list

By the numbers

  • Documents 5 profiling approaches: flamegraph, cargo-instruments, heaptrack, Criterion benches, and valgrind cachegrind

Files

SKILL.mdMarkdownGitHub ↗

Performance Optimization

Layer 2: Design Choices

Core Question

What's the bottleneck, and is optimization worth it?

Before optimizing:

  • Have you measured? (Don't guess)
  • What's the acceptable performance?
  • Will optimization add complexity?

---

Performance Decision → Implementation

GoalDesign ChoiceImplementation
Reduce allocationsPre-allocate, reusewith_capacity, object pools
Improve cacheContiguous dataVec, SmallVec
ParallelizeData parallelismrayon, threads
Avoid copiesZero-copyReferences, Cow<T>
Reduce indirectionInline datasmallvec, arrays

---

Thinking Prompt

Before optimizing:

1. Have you measured?

  • Profile first → flamegraph, perf
  • Benchmark → criterion, cargo bench
  • Identify actual hotspots

2. What's the priority?

  • Algorithm (10x-1000x improvement)
  • Data structure (2x-10x)
  • Allocation (2x-5x)
  • Cache (1.5x-3x)

3. What's the trade-off?

  • Complexity vs speed
  • Memory vs CPU
  • Latency vs throughput

---

Trace Up ↑

To domain constraints (Layer 3):

"How fast does this need to be?"
    ↑ Ask: What's the performance SLA?
    ↑ Check: domain-* (latency requirements)
    ↑ Check: Business requirements (acceptable response time)
QuestionTrace ToAsk
Latency requirementsdomain-*What's acceptable response time?
Throughput needsdomain-*How many requests per second?
Memory constraintsdomain-*What's the memory budget?

---

Trace Down ↓

To implementation (Layer 1):

"Need to reduce allocations"
    ↓ m01-ownership: Use references, avoid clone
    ↓ m02-resource: Pre-allocate with_capacity

"Need to parallelize"
    ↓ m07-concurrency: Choose rayon or threads
    ↓ m07-concurrency: Consider async for I/O-bound

"Need cache efficiency"
    ↓ Data layout: Prefer Vec over HashMap when possible
    ↓ Access patterns: Sequential over random access

---

Quick Reference

ToolPurpose
cargo benchMicro-benchmarks
criterionStatistical benchmarks
perf / flamegraphCPU profiling
heaptrackAllocation tracking
valgrind / cachegrindCache analysis

Optimization Priority

1. Algorithm choice     (10x - 1000x)
2. Data structure       (2x - 10x)
3. Allocation reduction (2x - 5x)
4. Cache optimization   (1.5x - 3x)
5. SIMD/Parallelism     (2x - 8x)

Common Techniques

TechniqueWhenHow
Pre-allocationKnown sizeVec::with_capacity(n)
Avoid cloningHot pathsUse references or Cow<T>
Batch operationsMany small opsCollect then process
SmallVecUsually smallsmallvec::SmallVec<[T; N]>
Inline buffersFixed-size dataArrays over Vec

---

Common Mistakes

MistakeWhy WrongBetter
Optimize without profilingWrong targetProfile first
Benchmark in debug modeMeaninglessAlways --release
Use LinkedListCache unfriendlyVec or VecDeque
Hidden .clone()Unnecessary allocsUse references
Premature optimizationWasted effortMake it work first

---

Anti-Patterns

Anti-PatternWhy BadBetter
Clone to avoid lifetimesPerformance costProper ownership
Box everythingIndirection costStack when possible
HashMap for small setsOverheadVec with linear search
String concat in loopO(n^2)String::with_capacity or format!

---

Related Skills

WhenSee
Reducing clonesm01-ownership
Concurrency optionsm07-concurrency
Smart pointer choicem02-resource
Domain requirementsdomain-*

Related skills

How it compares

Choose m10-performance over general Rust coding skills when the bottleneck is measurable latency or memory rather than compiler errors or API design.

FAQ

Which profiling tools does m10-performance recommend for Rust?

m10-performance recommends cargo flamegraph for CPU profiling, cargo-instruments on macOS and heaptrack on Linux for memory, Criterion via cargo bench for micro-benchmarks, and valgrind --tool=cachegrind for cache analysis on release binaries.

When should developers use Criterion in m10-performance?

m10-performance uses Criterion when comparing two Rust implementations on the same input, defining bench_function cases inside criterion_group blocks so parse_v1 and parse_v2 throughput can be measured side by side before choosing an optimization.

Is M10 Performance safe to install?

skills.sh reports 2 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Pythonbackenddevopsintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.