Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace hash_gid with FNV-1a #422

Open
wants to merge 2 commits into
base: rolling
Choose a base branch
from
Open

Conversation

fuzzypixelz
Copy link
Contributor

hash_gid is called on Zenoh subscriber callbacks and shows up when profiling as a hot function. The use of std::stringstream seems to be relatively inefficient. A significant portion of hash_gid's running time is spend allocating & deallocating the std::stringstream.

Screenshot 2025-01-15 at 17 39 31

@fuzzypixelz
Copy link
Contributor Author

We seem to have many uses of std::unordered_map where the hashing is done manually instead of relying on the Hash template parameter. I'll revisit that before marking this pull request as ready for review.

@fuzzypixelz fuzzypixelz marked this pull request as ready for review January 16, 2025 17:38
Copy link
Collaborator

@clalancette clalancette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a question inline.

Comment on lines +278 to +285
// This function implemented FNV-1a 64-bit as the GID is small enough
// (e.g. as of commit db4d05e of ros2/rmw RMW_GID_STORAGE_SIZE is set to 16)
// and FNV is known to be efficient in such cases.
//
// See https://github.com/ros2/rmw/blob/db4d05e/rmw/include/rmw/types.h#L44
// and https://datatracker.ietf.org/doc/html/draft-eastlake-fnv-17.html
static constexpr uint64_t FNV_OFFSET_BASIS_64 = 0x00000100000001b3;
static constexpr uint64_t FNV_PRIME_64 = 0xcbf29ce484222325;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we are already using xxhash3 in liveliness_utils to take a string and hash it into a 128-bit quantity. Do we need to hash again? In other words, could we just use the 128-bit GID directly and use that as the key?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants