-
Notifications
You must be signed in to change notification settings - Fork 847
Perf: Fix mis-usage of Arena in HPACK #6495
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,3 +200,56 @@ xpack_encode_string(uint8_t *buf_start, const uint8_t *buf_end, const char *valu | |
|
|
||
| return p - buf_start; | ||
| } | ||
|
|
||
| int64_t | ||
| xpack_encode_string(Arena &arena, uint8_t *buf_start, const uint8_t *buf_end, const char *value, uint64_t value_len, uint8_t n) | ||
| { | ||
| uint8_t *p = buf_start; | ||
| bool use_huffman = true; | ||
| char *data = nullptr; | ||
| int64_t data_len = 0; | ||
|
|
||
| // TODO Choose whether to use Huffman encoding wisely | ||
| // cppcheck-suppress knownConditionTrueFalse; leaving "use_huffman" for wise huffman usage in the future | ||
| if (use_huffman && value_len) { | ||
| data = arena.str_alloc(value_len * 4); | ||
| data_len = huffman_encode(reinterpret_cast<uint8_t *>(data), reinterpret_cast<const uint8_t *>(value), value_len); | ||
| } | ||
|
|
||
| // Length | ||
| const int64_t len = xpack_encode_integer(p, buf_end, data_len, n); | ||
| if (len == -1) { | ||
| if (use_huffman && value_len) { | ||
| arena.str_free(data); | ||
| } | ||
|
|
||
| return -1; | ||
| } | ||
|
|
||
| if (use_huffman) { | ||
| *p |= 0x01 << n; | ||
| } else { | ||
| *p &= ~(0x01 << n); | ||
| } | ||
| p += len; | ||
|
|
||
| if (buf_end < p || buf_end - p < data_len) { | ||
| if (use_huffman && value_len) { | ||
| arena.str_free(data); | ||
| } | ||
|
|
||
| return -1; | ||
| } | ||
|
|
||
| // Value | ||
| if (data_len) { | ||
| memcpy(p, data, data_len); | ||
| p += data_len; | ||
| } | ||
|
|
||
| if (use_huffman && value_len) { | ||
| arena.str_free(data); | ||
| } | ||
|
|
||
| return p - buf_start; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alternative to using an arena here would be something like: (Where 1024 is the default arena block size.). I'm guessing it would have better performance in the most likely scenarios.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks smarter than what I told as alternative approach (switching |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use https://github.com/apache/trafficserver/blob/master/include/tscpp/util/PostScript.h to avoid having to repeat this free 3 times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know we have this. I was thinking to introduce "defer" like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dr. Zret picked the name PostScript.