In parallel, would the libs team be amenable to exploring what if we changed the implementations of
[u8]? They currently both hash their contents, and additionally a sentinel value, to help hashes of tuples or structs that have different strings not have the same hash.
For example, the current impls make it so, with a
struct Thing(&'static str, &'static str), a
Thing("foobar", "baz") and
Thing("foo", "barbaz") do not have the same hash output. Unfortunately, that means hashing
"foo" results in 2 calls to
Hasher.hash(), slowing it down.
Changing this behavior would mean single strings would only call
hash once, and be faster. Structs and tuples that include multiple string fields would have the possibility of hitting a hash collision, but they still should not
eq each other. It would shift the cost from "every single string, all the time", to "when a struct with multiple strings has a collision, handle the collision". This change appears to prioritize the common case, leaving the slow case to the "quite unlikely case".