From: Willy Tarreau Date: Tue, 11 Dec 2018 05:42:01 +0000 (+0100) Subject: MINOR: hpack: optimize header encoding for short names X-Git-Tag: v1.9-dev11~129 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19ed92b;p=thirdparty%2Fhaproxy.git 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%. --- diff --git a/src/hpack-enc.c b/src/hpack-enc.c index 73a5fd1671..dd0d0ab247 100644 --- a/src/hpack-enc.c +++ b/src/hpack-enc.c @@ -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);