We love pull-requests ;)

> Am 24.03.2014 um 13:26 schrieb Alexey notifications@github.com:
> 
> Hi
> 
> https://github.com/netty/netty/blob/4.0/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrepender.java
> 
> Now we calculate headerLen for start, and some later create CodedOutputStream with code
> 
> CodedOutputStream headerOut =
>                 CodedOutputStream.newInstance(new ByteBufOutputStream(out));
> default constructor allocate 4096 buffer, but headerLen always less than 5.
> More correct way it's set size of buffer for new instance with code:
> 
> CodedOutputStream headerOut =
>                 CodedOutputStream.newInstance(new ByteBufOutputStream(out), headerLen);
> this decrease allocation for header prepender from 4096 bytes to [1-5] bytes for every protobuf message
> 
> —
> Reply to this email directly or view it on GitHub.
 how i can remove first "referenced this issue from a commit in"
because he have incorrect committer and i did't pull request for he =\

pull request: [#2340]
 Close it an open a new one? Also please update tge commit message to match tge template we use.

> Am 24.03.2014 um 16:44 schrieb Alexey notifications@github.com:
> 
> how i can remove first pull request,
> because he have incorrect committer and i did't pull request for he =\
> 
> —
> Reply to this email directly or view it on GitHub.

reduce memory usage in ProtobufVarint32LengthFieldPrepender.java
Hi

https://github.com/netty/netty/blob/4.0/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrepender.java

Now we calculate headerLen for start, and some later create CodedOutputStream with code

```
CodedOutputStream headerOut =
                CodedOutputStream.newInstance(new ByteBufOutputStream(out));
```

default constructor allocate 4096 buffer, but headerLen always less than 5.
More correct way it's set size of buffer for new instance with code:

```
CodedOutputStream headerOut =
                CodedOutputStream.newInstance(new ByteBufOutputStream(out), headerLen);
```

this decrease allocation for header prepender from 4096 bytes to [1-5] bytes for every protobuf message

codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrepender.java
codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrepender.java
diff --git a/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrepender.java b/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrepender.java
index b9231781d80..9efd00ff269 100644
--- a/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrepender.java
+++ b/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrepender.java
@@ -47,7 +47,7 @@ protected void encode(
         out.ensureWritable(headerLen + bodyLen);
 
         CodedOutputStream headerOut =
-                CodedOutputStream.newInstance(new ByteBufOutputStream(out));
+                CodedOutputStream.newInstance(new ByteBufOutputStream(out), headerLen);
         headerOut.writeRawVarint32(bodyLen);
         headerOut.flush();
 
