title: Protobuf getAllFields() performance
body: <p>We are using protobuf as our messaging, and each message, we loop thru the set fields, and do something with it.</p>
  
  <p>We loop it using</p>
  
  <pre><code>    for ( final Map.Entry&lt;Descriptors.FieldDescriptor, Object&gt; entry : msg.getAllFields().entrySet()) {
              FieldDescriptor field = entry.getKey();
              Object value = entry.getValue();
  </code></pre>
  
  <p>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.</p>
  
  <p>I know that we can use do something like this:</p>
  
  <pre><code>    for ( final FieldDescriptor field : msg.getDescriptorForType().getFields()) {
          if (!msg.hasField(field)){
              continue;
          }
          Object value = message.getField(field);
  </code></pre>
  
  <p>But getDescriptorForType returns all the fields rather than just the set ones.</p>
  
  <p>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?</p>
  
  <p>Thanks.</p>