From af4f70ba2807843a63fb325d36a8f8123d9c9fa6 Mon Sep 17 00:00:00 2001 From: Michael Nitschinger Date: Mon, 25 Jan 2016 14:05:57 +0100 Subject: [PATCH] More efficiently allocate header buffer. Motivation ---------- Currently, only the fixed 24 bytes are allocated for the header and then all the params as well as the optional extras and key are written into the header section. It is very likely that the buffer needs to expand at least two times if either the extras and/or the key take up more space. Modifications ------------- Since at the point of allocation we know the key and extras length, the buffer can be preallocated with the exact size, avoiding unnecessary resizing and even allocating too much (since it uses power of two internally). Result ------ Less buffer resizing needed when encoding a memcache operation. --- .../codec/memcache/binary/AbstractBinaryMemcacheEncoder.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/AbstractBinaryMemcacheEncoder.java b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/AbstractBinaryMemcacheEncoder.java index 367383b498..dd5e4c9eed 100644 --- a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/AbstractBinaryMemcacheEncoder.java +++ b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/AbstractBinaryMemcacheEncoder.java @@ -30,11 +30,12 @@ public abstract class AbstractBinaryMemcacheEncoder