Benchmark backing the camino PR that delegates Utf8Path::hash to the wrapped
std::path::Path instead of iterating self.components().
Today impl Hash for Utf8Path walks the std::path::Components iterator and
hashes each component separately. The wrapped Path::hash does the same job in a
single-pass byte scan and is already consistent with eq (which compares
components), so delegating to it is both correct and cheaper.
| strategy | Ir / hash |
|---|---|
hash_components (current: self.components()) |
~1157 |
hash_inner (proposed: self.0.hash) |
~553 |
~2.1x fewer instructions. std::path::Components::next alone is ~40% of the
benchmark — pure traversal overhead the delegation removes. See
callgrind-fxhash.txt.
Drop hash.rs into benches/ of a camino checkout and add to Cargo.toml:
[dev-dependencies]
rustc-hash = "2"
[[bench]]
name = "hash"
harness = falseBuild and profile under callgrind (Linux):
cargo build --release --bench hash
BIN=$(ls -t target/release/deps/hash-* | grep -vE '\.(d|o)$' | head -1)
valgrind --tool=callgrind --instr-atstart=yes --cache-sim=no \
--callgrind-out-file=callgrind.out "$BIN"
callgrind_annotate --inclusive=yes callgrind.out | grep hash::hash_