Reviewer · Performance Optimization
Benchmark-driven optimization
Treat performance changes as hypotheses that must be validated with real measurements, not intuition. Before changing an algorithm, data structure, default (e.g. worker/thread counts), or caching strategy for speed or memory, profile the before/after behavior with representative real-world workloads (not just a microbenchmark), and include the methodology...
Treat performance changes as hypotheses that must be validated with real measurements, not intuition. Before changing an algorithm, data structure, default (e.g. worker/thread counts), or caching strategy for speed or memory, profile the before/after behavior with representative real-world workloads (not just a microbenchmark), and include the methodology and results in the PR description so reviewers can judge the trade-off. For example, the default checkout.workers value of 8 was chosen only after benchmarking checkout time across repos ranging from 400 to 180k files; the dependency_queue scheduler change was justified by showing both “no measurable end-to-end improvement” on Cargo’s own workspace and a large asymptotic win (4.5x–270x) for wide ready-frontiers; and a cargo clean dedup optimization was tuned by comparing memory/time trade-offs between a plain HashSet, a HashSet restricted to files with nlink > 1, and a bloom filter.
When the measured impact is small, inconclusive, or only a microbenchmark without end-to-end evidence, prefer the simpler/more readable implementation and only revisit it if a real regression is later observed (as with the ConfigLoader::load_unmerged_from splice-vs-extend choice). Avoid adding complexity (e.g. new allocation-saving code, duplicate work elimination) unless it is profiled on the actual hot path; unproven micro-optimizations that add complexity without demonstrated impact should not be merged.
Be explicit about trade-offs between correctness/determinism, memory, and speed: deliberately scoped fixes (e.g. excluding host-only deps from -C metadata but not unit_id) can resolve one problem while reintroducing performance or cache-locality issues elsewhere (e.g. breaking caching, or LTO reproducibility), so document why a narrower fix was chosen over a more “complete” one. Similarly, when picking between approaches with different resource profiles (e.g. a custom FileId vs same_file::Handle, which opens every file and can exhaust file descriptors on large directories), add a comment explaining the constraint so future refactors don’t reintroduce the problem. Finally, eliminate genuinely redundant expensive work (e.g. duplicate external process invocations) by reusing already-computed/cached results rather than recomputing them per call-site.