This is a use case that is, unfortunately, not well-optimized by the Java
implementation. What's needed is versions of ArrayList which store unboxed
values. Unfortunately, a separate such implementation would be needed for
every primitive field type, since Java generics work only with boxed types.
It will be tedious, but you're welcome to work on it.
On Tue, Jun 22, 2010 at 7:16 PM, Joshua Hartman <atomicfo...@gmail.com>wrote:
> I'm trying to serialize a large primitive array of int in Java, and
> I'm testing using 1,000,000 elements. My .proto message is just a
> packed repeated field of type int32. To serialize, I just create a
> builder and loop through the array, adding elements one at a time. I
> took a peek at the underlying implementation and it seems that it uses
> an ArrayList. However, there's no way to reserve the size of the
> ArrayList, so serializing is slower than it could be. In fact, it's
> faster for me to just serialize the data an ObjectOutputStream to put
> the data in a protocol buffer bytes message.
> Is there a way for me to do the serialization faster? I took a peek
> through the API but didn't see anything obvious. I saw
> CodedOutputStream as well, but I didn't understand the intent of that
> class. Could anyone please explain what it's used for?
> Josh H
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to proto...@googlegroups.com.
> To unsubscribe from this group, send email to
> For more options, visit this group at
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to
For more options, visit this group at