]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hpack: optimize header encoding for short names
authorWilly Tarreau <w@1wt.eu>
Tue, 11 Dec 2018 05:42:01 +0000 (06:42 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 11 Dec 2018 08:06:46 +0000 (09:06 +0100)
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%.

src/hpack-enc.c

index 73a5fd16718f76db5a0891055ed95dcaa9cca122..dd0d0ab247963a87e1ab6c2e8dd4f7ee7033fefb 100644 (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);