Status: New
Owner: liuj...@google.com
Labels: Type-Defect Priority-Medium

New issue 464 by ryan.fog...@gmail.com: Inefficient Java handling of repeated list of primitive types
http://code.google.com/p/protobuf/issues/detail?id=464

What steps will reproduce the problem?
1. Any handling of Protobuf message with a large set of repeated primitive fields ([packed=true] or not).
For instance:

messages Foo {
  ...
  repeated float data = 10; // optionally [packed=true]
}

2. Create handler that deals with large numbers of Foos with large data.
3. Use a profiler to monitor the large number of autoboxed types that slam the GC.

What is the expected output? What do you see instead?
The output is as expected, except the Java garbage collector is slammed because of having to manage a large number autoboxed primitive wrappers because of the use of a java.util.List Collection as the code-generated field type.


What version of the product are you using? On what operating system?
2.4.0a, 2.4.1, but confirmed that inefficiencty still exists in 2.5.0. Linux/RedHat, Java 1.6.X.

Please provide any additional information below.
I have attached a (bzipped) patch file that has a solution that uses a backend primitive_type[] that grows linearly as needed (much like a deque). It avoids having to generate autoboxed wrappers for repeated primitive types thus alleviating tons of work by the GC. Also, exposed a new interface that breaks immutability at the expense of performance by allowing the array[] type to be returned so that a client can make use of functions such as System.copy. If preserving immutability is absolutely mandatory then it may be necessary to provide a copy function (which takes an array_type[] reference as its argument) or incur an additional array clone/copy before returning the data (probably not the preferred approach).

Enquired about this on the Google Groups protobuf forum months ago but only got a single response that someone would be interested in the fix. Link to that conversation is here:
https://groups.google.com/d/msg/protobuf/w8lYLRW1wLY/cFbCMkknIHgJ


Attachments:
        java_primitive_field.cc.patch.bz2  2.8 KB

--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to