
On 12/6/24 00:18, Ivan Matek via Boost wrote:
I did not paste std::string results since as mentioned they are mostly influenced by clang inlining decisions, but you get the idea: there seems to be small but real performance difference when hashing size. I checked what some other popular C++ non std library does for std::string_view when it is implementing replacement for std::hash and it also hashes size, so I presume it is not unreasonable that boost does same, but I wonder if we could do something faster.
Technically, it doesn't need to be size to separate the two fields. You can use any kind of separator, including a fixed one (i.e. not depending on either of the fields it separates). I.e. instead of this: "ab" | 2 | "c" | 1 you could have this: "ab" | separator_t{} | "c" | separator_t{} An empty sequence could simply be hashed as separator_t{}. The question is how separator_t would hash and whether it could be made any faster than just hashing the size. I suppose, it could be smaller (e.g. 1 byte of data instead of sizeof(size_t)), but I'm not sure if that would mean anything in terms of performance.