From d66cd24206dd1b27f486f9d2dfc0d0fc94d2bce2 Mon Sep 17 00:00:00 2001 From: George Barnett Date: Thu, 16 May 2019 14:31:19 +0100 Subject: [PATCH] Reserve capacity when decoding HPACK headers (#118) Motivation: I was seeing frequent reallocations of the headers array as it resized during decoding. Modifications: Reserve capacity for at least 16 HPACK headers during decoding. Result: Fewer reallocations at the cost of allocating more than we might need. --- Sources/NIOHPACK/HPACKDecoder.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/NIOHPACK/HPACKDecoder.swift b/Sources/NIOHPACK/HPACKDecoder.swift index 8c61818..9046b8c 100644 --- a/Sources/NIOHPACK/HPACKDecoder.swift +++ b/Sources/NIOHPACK/HPACKDecoder.swift @@ -89,6 +89,7 @@ public struct HPACKDecoder { // take a local copy to mutate var bufCopy = buffer var headers: [HPACKHeader] = [] + headers.reserveCapacity(16) while bufCopy.readableBytes > 0 { switch try self.decodeHeader(from: &bufCopy) {