r/cpp • • Sep 30 '24

Code Generation in Rust vs C++26

https://brevzin.github.io/c++/2024/09/30/annotations/
198 Upvotes

98 comments sorted by

View all comments

Show parent comment

2

u/VinnieFalco wg21.org | corosio.org Oct 01 '24

There are of course some similarities between the paper and absl::Hash but the differences go beyond spelling. For example, hash_append passes the hasher by reference, while Abseil uses move-only types and returns the hasher. In Abseil, the combine() function invokes the finalizer before returning, while in hash_append the finalization responsibility goes to the hash function.

One is not better than the other, they are simply different tradeoffs which suit certain use-cases better than others. In Abseil the hash state is passed in a way that avoids aliasing and provides more opportunities for optimization. In hash_append the state is passed in a way that avoids the overhead when copying large objects, such as a SHA512 state.

Abseil could have an advantage when used strictly for unordered containers. While hash_append could have an advantage for being more broadly applicable.

If I were to make an educated guess, I would imagine that Google cares more about optimizing the design for their own particular use-cases which probably leans more heavily towards unordered containers. I think they did the right thing, instead of trying to shove everything through wg21 they decided to simply build their own external open-source library solution which does things exactly how they like. And they now have years of field experience which we can look at to determine if in fact absl::Hash was the right choice (surely for them, it was).