On Tue, May 19, 2015 at 9:13 PM, Tak Wong <yek...@gmail.com> wrote:

> We are using protobuf as our messaging, and each message, we loop thru the
> set fields, and do something with it.
>
> We loop it using
>
>     for ( final Map.Entry<Descriptors.FieldDescriptor, Object> entry : 
> msg.getAllFields().entrySet()) {
>             FieldDescriptor field = entry.getKey();
>             Object value = entry.getValue();
>
> Under profiler, we found that this GetAllFields uses most of the time, and
> I did some research, and it looks like there is no other way.
>
> I know that we can use do something like this:
>
>     for ( final FieldDescriptor field : 
> msg.getDescriptorForType().getFields()) {
>         if (!msg.hasField(field)){
>             continue;
>         }
>         Object value = message.getField(field);
>
> But getDescriptorForType returns all the fields rather than just the set
> ones.
>
> Does anyone know of another better performing way to loop thru the fields?
> I believe the problem with getAllFields are creating a new map each time,
> and also reflection. Can i force it to use Trove map inside rather than a
> regular hashmap?
>
Protobuf reflection API is known to be slower than generated API. You can
consider manually checking the fields of a message. That would be much
faster than getAllFields().



> Thanks.
>
>  --
> 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 protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at http://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to