MINOR: hpack: optimize header encoding for short names

For unknown fields, since we know that most of them are less than 127
characters, we don't need to go through the loop and can instead directly
emit the one-byte length encoding. This increases the request rate by
approximately 0.5%.
This commit is contained in:
Willy Tarreau 2018-12-11 06:42:01 +01:00
parent ac73ae0b83
commit 19ed92b47d

View File

@ -114,6 +114,12 @@ int hpack_encode_header(struct buffer *out, const struct ist n,
out->area[len++] = 0x58; // literal with indexing -- name="cache-control" (idx 24)
else if (isteq(n, ist("content-length")))
out->area[len++] = 0x5c; // literal with indexing -- name="content-length" (idx 28)
else if (likely(n.len < 127 && len + 1 + n.len <= size)) {
out->area[len++] = 0x00; /* literal without indexing -- new name */
out->area[len++] = n.len; /* single-byte length encoding */
ist2bin(out->area + len, n);
len += n.len;
}
else if (len_to_bytes(n.len) && len + 1 + len_to_bytes(n.len) + n.len <= size) {
out->area[len++] = 0x00; /* literal without indexing -- new name */
len = hpack_encode_len(out->area, len, n.len);