On Fri, Sep 25, 2009 at 6:41 AM, Daniel Augustin Pavel <
daniel.pa...@gmail.com> wrote:

> Hello,
>
> I've worked a bit on improving the perfomance of equals() and
> hashCode() for the generated message clases.
>

Cool!

Unfortunately, increasing the generated code size really is a big problem.
 Protobuf generated code is *huge*, and we're always looking for ways to
reduce it.  We made a conscious decision not to implement equals() and
hashCode() in generated code because, in our experience, these methods are
rarely actually desired outside of tests, so the benefit of reducing the
generated code size outweighs the cost of these methods being slow.

Can you tell us a bit about your use case?  Again, in my experience, people
who are comparing message objects by content outside of tests are almost
always doing something they don't need to be (usually they actually want to
compare by identity instead).  But, I'm willing to be proven wrong.

BTW, another way you could possibly speed up equals() and hashCode() is to
serialize the objects and compare raw bytes.  This can be done pretty easily
in a wrapper class, without modifying the protobuf implementation.  You
could also implement your hash-caching trick in a wrapper class, which alone
could probably make a huge difference for List.contains().  Or we could
perhaps implement the hash caching in the official implementation, since it
wouldn't require new generated code.


> The above does not apply to LITE messages from what I can tell, they
> just use the standard Object implementation of these methods (which I
> find quite inappropiate for the kind of data protobuf objects are
> supposed to represent).
>

The goal of "lite" messages is to shed features in order to reduce code
size.  equals() and hashCode() were two of the casualties.  Since lite
messages don't support reflection, our options were either to generate more
code (bad -- lite users are exactly the users who don't want more code) or
not implement them.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to