You can control whether the vector is empty or not: you can reserve memory for the vector based on the descriptor size, or reuse a vector previously passed to ListFields - calling vector::clear() does not delete the allocated memory.
Admittedly, the reflection code is not heavily optimized. But any choice of container is likely to run into some issues; there just hasn't been much effort into picking these tradeoffs. In general messages are encouraged to be small so that the allocation size for the output vector should not be that significant. On Fri, Sep 7, 2012 at 2:54 AM, jaycee <xujay...@gmail.com> wrote: > When using protobuf , there comes the performance bottleneck. > Then I found the hot point is focus on > GeneratedMessageReflection::ListFields (which costs 30%+ CPU idle) by > gprofiler, which indicates that there is too much "new" and "delete" . > > ------------------------API of ListFields--------------------------------- > void > GeneratedMessageReflection::ListFields( > > const Message& > message, > > vector<const FieldDescriptor*>* output) const; > > --------------------------------------------------------------------------------- > > As the function called, the second arg : "output" is always a empty > vector. So it will cause new/delete for many times in case of plenty fields > So as title mentioned, Why don't we use deque or other container to avoid > too much new/delte, instead of using vector. > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/protobuf/-/AhsFq2N6IxEJ. > 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. > -- 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.