Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Java deserialization - any best practices for performances?

MIME-Version: 1.0
Received: by 10.100.248.16 with SMTP id v16mr506616anh.0.1248334368386; Thu, 
	23 Jul 2009 00:32:48 -0700 (PDT)
Date: Thu, 23 Jul 2009 00:32:48 -0700 (PDT)
In-Reply-To: <4112ecad0907181822n25304a0bm7cd5631a3d9b38aa@mail.gmail.com>
X-IP: 67.83.207.24
References: <0a09c6cc-e350-46ac-a673-b01ffc7dbb8b@d4g2000yqa.googlegroups.com> 
	<4112ecad0907181822n25304a0bm7cd5631a3d9b38aa@mail.gmail.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; 
	rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1,gzip(gfe),gzip(gfe)
Message-ID: <cbefd288-8654-448a-b6f0-2b062ee4ba85@j32g2000yqh.googlegroups.com>
Subject: Re: Java deserialization - any best practices for performances?
From: alopecoid <alopec...@gmail.com>
To: Protocol Buffers <protobuf@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi,

I haven't actually used the Java protobuf API, but it seems to me from
the quick occasional glance that this isn't entirely true. I mean,
specifically in response to the code snippet posted in the original
message, I would possibly:

1. Reuse the Builder object by calling its clear() method. This would
save from the need to create a new Builder object for each iteration
of the outermost loop.

2. Iterate over the repeated field using the get*Count() and get*
(index) methods instead of the get*List() method. I'm not sure if this
would save anything, but depending on how things are implemented in
the generated code, this could save from allocating a new List object.

Also, might "bytes" type fields perform better than any "string" type
fields that you may have in your particular data set? I'm not sure,
but it might be worth benchmarking.

On Jul 18, 9:22=A0pm, Kenton Varda <ken...@google.com> wrote:
> On Fri, Jul 17, 2009 at 8:13 PM, Alex Black <a...@alexblack.ca> wrote:
>
> > When I write out messages using C++ I'm careful to clear messages and
> > re-use them, is there something equivalent on the java side when
> > reading those same messages in?
>
> No. =A0Sorry. =A0This just doesn't fit at all with the Java library's des=
ign,
> and even if it did, you cannot reuse Java String objects, which often
> account for most of the memory usage. =A0However, memory allocation is ch=
eaper
> in Java than in C++, so there's less to gain from it.
>
>
>
> > My code looks like:
>
> > CodedInputStream stream =3D CodedInputStream.newInstance(inputStream);
>
> > while ( !stream.isAtEnd() )
> > {
> > =A0 =A0 MyMessage.Builder builder =3D MyMessage.newBuilder();
> > =A0 =A0 stream.readMessage(builder, null);
> > =A0 =A0 MyMessage myMessage =3D builder.build();
>
> > =A0 =A0 for ( MessageValue messageValue : myMessage.getValuesList() )
> > =A0 =A0 {
> > =A0 =A0 =A0 =A0......
> > =A0 =A0 }
> > }
>
> > I'm passing 150 messages each with 1000 items, so presumably memory is
> > allocated 150 times for each of the messages...
>