Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Guides writing and reviewing idiomatic Rust using Apollo GraphQL's best practices handbook: ownership, errors, performance, testing, docs.
78% 96%+17 ptsof test cases passed
Passed 22 of 23 test cases with the skill, and 18 of 23 without it.
3 of 3 safety checks passed
Not used yet
The golden rule of performance work:
Don't guess, measure.
Rust code is often already pretty fast - don't "optimize" without evidence. Optimize only after finding bottlenecks.
--release flag on your builds (might sound dummy, but it is quite common to hear people complaining that their Rust code is slower than their X language code, and 99% of the time is because they didn't use the --release flag).$ cargo clippy -- -D clippy::perf gives you important tips on best practices for performance.cargo bench is a cargo tool to create micro-benchmarks and test different code solutions. Write a test scenario and bench your solution against the original code, if your improvement is larger than 5%, might be a good performance improvement.cargo flamegraph a powerful profiler for Rust code. For MacOS, samply might be a better DX option.Further reading on Benchmarking:
Flamegraph helps you visualize how much time CPU spent on each task.
# Installing flamegraph
cargo install flamegraph
# cargo support provided through the cargo-flamegraph binary!
# defaults to profiling cargo run --release
cargo flamegraph
# by default, `--release` profile is used,
# but you can override this:
cargo flamegraph --dev
# if you'd like to profile a specific binary:
cargo flamegraph --bin=stress2
# Profile unit tests.
# Note that a separating `--` is necessary if `--unit-test` is the last flag.
cargo flamegraph --unit-test -- test::in::package::with::single::crate
Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.