roger peppe writes: > the documentation says, on writing fields in order: "This allows > parsing code to use optimizations > that rely on field numbers being in sequence." > > what optimizations might these be? > does the current implementation use any such optimizations? > what penalty do i pay by *not* writing fields in order?
The C++ generator does this. If you look at some of the generated MergePartialFromCodedStream() methods, you can see how this is done. The code peeks at the next tag, and if it has the expected (in-sequence) value, needs only a single conditional branch to go to the correct handler. If the fields are not in order, the parser must find the correct handler through a switch statement. Due to the difficulty of predicting the path that will be taken by that switch, this can save considerable time on deeply pipelined CPUs. Michael Poole --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~----------~----~----~----~------~----~------~--~---