The fast path only works if the "optimize_for" option is set to "SPEED" in
the proto file. If that's not the case, just use approach 2.
If you enabled the "optimize_for" option and want to take advantage of the
fast path, 3) seems to be a reasonable approach. The code should be similar
to the implementation of WireFormatLite::WriteMessageMaybeToArray(). Maybe
we can just add a WireFormatLite::WriteMessageNoTagMaybeToArray().

On Wed, Jun 26, 2013 at 8:17 AM, Hochhaus, Andrew <[email protected]>wrote:

> Does anyone have any insight on Evan's "related question" below?
>
> On Thu, Jun 17, 2010 at 5:05 PM, Evan Jones <[email protected]> wrote:
> > Related question: If I am writing length-prefixed values, what is the
> "best"
> > way to do this? I think there are 3 approaches:
> >
> > 1. out.WriteVarint32(msg.ByteSize()); msg.SerializeToCodedStream(&out);
> >
> > This approach will choose between the "ToArray" and "regular" versions of
> > the Serialize method, as appropriate. However, it computes the ByteSize
> > twice.
> >
> > 2. out.WriteVarint32(msg.ByteSize()); msg.SerializeWithCachedSizes(&out);
> >
> > This computes the ByteSize once, but never uses the "fast path" ToArray
> > method.
> >
> > 3. Some custom code that calls ByteSize once, then chooses between the
> > "fast" and "slow" methods, as appropriate. Is there actually any
> significant
> > difference in performance between SerializeWithCachedSizes and
> > SerializeWithCachedSizesToArray, so it would be worth me actually doing
> > this?
>
> -Andy
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to