Skip to content

ring hash: optimize hash key build#2284

Merged
htuch merged 3 commits intomasterfrom
more_ring_hash_perf
Jan 1, 2018
Merged

ring hash: optimize hash key build#2284
htuch merged 3 commits intomasterfrom
more_ring_hash_perf

Conversation

@mattklein123
Copy link
Member

Avoid string copies during the inner loop of the ring build.

Risk Level: Low
Testing: Existing unit tests
Docs Changes: N/A
Release Notes: N/A

Signed-off-by: Matt Klein <mklein@lyft.com>
htuch
htuch previously approved these changes Dec 31, 2017
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Nice.

// buffer on the heap and use it for all calculations. The needed size is the size of the
// address, plus '_', plus 32 bytes for the index. All of this is done to avoid string
// allocations in the fast path.
const uint64_t needed_size = std::min(128UL, address_string.size() + 1 + 32);
Copy link
Member

Choose a reason for hiding this comment

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

Is there some constant we can use for max 64-bit representation? In the StringUtil::itoa comment it says this is 21 (including null), here we use 32 just to be safe (I think).

Copy link
Member Author

@mattklein123 mattklein123 Dec 31, 2017

Choose a reason for hiding this comment

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

Yeah I will add a constant. I realized this code has a bug, it should be std::max, not min. I'm going to redo it also to use https://github.com/abseil/abseil-cpp/blob/master/absl/container/inlined_vector.h which would make it stack allocated in most case and easier to read. Will also add a test that would catch the min/max issue. I will update all of it tomorrow.

Signed-off-by: Matt Klein <mklein@lyft.com>
@mattklein123
Copy link
Member Author

@htuch updated. I decided to take a simpler approach. Update comments also.

@htuch htuch merged commit bb4734c into master Jan 1, 2018
@htuch htuch deleted the more_ring_hash_perf branch January 1, 2018 13:27
jpsim added a commit that referenced this pull request Nov 28, 2022
Follow-up to envoyproxy/envoy-mobile#2277.

Signed-off-by: JP Simard <jp@jpsim.com>
jpsim added a commit that referenced this pull request Nov 29, 2022
Follow-up to envoyproxy/envoy-mobile#2277.

Signed-off-by: JP Simard <jp@jpsim.com>
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.

2 participants