title: Google protocol buffers huge in python
body: <p>I started using the protocol buffer library, but noticed that it was using huge amounts of memory.  pympler.asizeof shows that a single one of my objects is about 76k!  Basically, it contains a few strings, some numbers, and some enums, and some optional lists of same.  If I were writing the same thing as a C-struct, I would expect it to be under a few hundred bytes, and indeed the ByteSize method returns 121 (the size of the serialized string).</p>
  
  <p>Is that you expect from the library?  I had heard it was slow, but this is unusable and makes me more inclined to believe I'm misusing it.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Here is an example I constructed.  This is a pb file similar, but simpler than what I've been using</p>
  
  <pre><code>    package pb;
  
  message A {
      required double a       = 1;
  }
  
  message B {
      required double b       = 1;
  }
  
  message C {
      required double c       = 1;
      optional string s       = 2;
  }
  
  message D {
      required string d       = 1;
      optional string e       = 2;
      required A a            = 3;
      optional B b            = 4;
      repeated C c            = 5;
  }
  </code></pre>
  
  <p>And here I am using it</p>
  
  <pre><code>&gt;&gt;&gt; import pb_pb2
  &gt;&gt;&gt; a = pb_pb2.D()
  &gt;&gt;&gt; a.d = "a"
  &gt;&gt;&gt; a.e = "e"
  &gt;&gt;&gt; a.a.a = 1
  &gt;&gt;&gt; a.b.b = 2
  &gt;&gt;&gt; c = a.c.add()
  &gt;&gt;&gt; c.c = 5
  &gt;&gt;&gt; c.s = "s"
  &gt;&gt;&gt; import pympler.asizeof
  &gt;&gt;&gt; pympler.asizeof.asizeof(a)
  21440
  &gt;&gt;&gt; a.ByteSize()
  42
  </code></pre>
  
  <p>I have version 2.2.0 of protobuf (a bit old at this point), and python 2.6.4.</p>