destroying a protocol buffer message in debug mode is almost 500 times slower than in release mode

53 views
Skip to first unread message

Chris Morris

unread,
Aug 7, 2012, 7:09:18 PM8/7/12
to prot...@googlegroups.com
Use the following file with your own timing code around the call to delete msg in main(). When running in debug mode, it is taking 473 times as long, on average, as when running without debugging.
I am using Visual Studio 2008 SP 1 on a Windows 7 machine.


#include "PropMsg.ph.h"
 
void RawSerializer::serialize(int i_val, PropMsg * o_msg)
{
        o_msg->set_v_int32(i_val);
}
void serialize(std::vector<int> const & i_val, PropMsg * o_msg)
{
    for (std::vector<int>::const_iterator it = i_val.begin(); it != i_val.end(); ++it) {
        PropMsg * objMsg = o_msg->add_v_var_repeated();
        serialize( * it, objMsg);
    }
}
 
int main()
{
    std::vector<int> testVec(100000);
    PropMsg * msg = new PropMsg;
    serialize(testVec, msg);
    delete msg; // Time this guy
}

PropMsg was created with the following .proto file definition:

option optimize_for = SPEED;
message PropMsg
{
  optional int32 v_int32 = 7;
  repeated PropMsg v_var_repeated = 101;
}

Eric J. Holtman

unread,
Aug 7, 2012, 7:12:32 PM8/7/12
to protobuf@googlegroups.com >> Protocol Buffers
On 8/7/2012 6:09 PM, Chris Morris wrote:
> Use the following file with your own timing code around the call to *delete
> msg* in main(). When running in debug mode, it is taking 473 times as long,
> on average, as when running without debugging.

Debugging mode generally has a ton more heap consistency checking.

Chris Morris

unread,
Aug 7, 2012, 7:16:08 PM8/7/12
to prot...@googlegroups.com
I forgot to ask my question:
Does anyone know why this is happening? If so, is there a way that I can get this code to run much faster in debug mode?

Eric J. Holtman

unread,
Aug 7, 2012, 7:39:22 PM8/7/12
to prot...@googlegroups.com
On 8/7/2012 6:16 PM, Chris Morris wrote:
> I forgot to ask my question:
> *Does anyone know why this is happening? If so, is there a way that I can
> get this code to run much faster in debug mode?*
>


You might be able to compile the protobuf modeules
without debugging..... beware that this opens up
a rat's nest of problems (if you "new" something
in one place and "delete" it elsewhere and the
debugging settings are different, you are in for
a world of hurt.
Reply all
Reply to author
Forward
0 new messages