- Home
- Skills
- Huiali
- Rust Skills
- Rust Performance
rust-performance_skill
- Shell
20
GitHub Stars
3
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill huiali/rust-skills --skill rust-performance- SKILL_EN.md1.7 KB
- SKILL_ZH.md6.8 KB
- SKILL.md8.1 KB
Overview
This skill is a Rust performance optimization expert that guides profiling, benchmarking, memory allocation, SIMD, cache layout, false sharing, lock contention, and NUMA-aware programming. It focuses on measurable improvements: identify hotspots, apply targeted changes, and verify gains with benchmarks and profiles. The approach emphasizes algorithm and data-structure selection first, then lower-level optimizations only where they matter.
How this skill works
I inspect runtime symptoms (high CPU, memory growth, latency), recommend the right profiling tool (perf, flamegraph, heaptrack, valgrind/dhat) and map hotspots to concrete corrective patterns. I propose prioritized fixes—algorithm or data-structure changes, pre-allocation, reducing clones, cache-line layout, sharding locks, SIMD/parallelism, and NUMA binding—and produce verification commands and benchmarks to confirm improvements.
When to use it
- Application exhibits high CPU, latency, or memory without clear cause
- Scaling across cores causes slowdown or high system time
- Observed high LLC misses, atomic contention, or mutex hotspots
- Deploying on multi-socket servers with NUMA-induced latency
- You need measurable throughput or tail-latency improvements
Best practices
- Profile before changing code; optimize hot paths only
- Prioritize algorithm and data-structure changes before micro-optimizations
- Pre-allocate buffers and batch I/O to reduce allocator pressure
- Avoid unnecessary clones and heap indirection; prefer stack or SmallVec for small items
- Shard data structures or use thread-local state to eliminate global lock contention
- Measure after each change with cargo bench and perf/flamegraph
Example use cases
- Speed up a hot loop by replacing O(n²) behavior with an O(n log n) algorithm and verifying with flamegraph and benches
- Fix threading slowdown by converting a global Mutex<HashMap> into per-thread local maps and merging at the end
- Resolve false sharing by aligning atomic counters to cache-line boundaries with repr(align(64))
- Reduce allocator pressure by switching frequent small allocations to object pools or SmallVec
- Improve multi-socket throughput by binding threads to NUMA nodes and using a NUMA-aware allocator
FAQ
Start with algorithm and data-structure selection; those yield the largest gains. Only optimize micro-level details after profiling confirms they’re on the hot path.
Which profiler to use for CPU vs memory vs cache?
Use perf + flamegraph for CPU hotspots, heaptrack or dhat for allocations, and valgrind --tool=cachegrind for cache analysis.