Python consumes a lot of memory – how to reduce the size of objects?
TXR Lisp, 64 bit:<p><pre><code>  1&gt; (defstruct blank ())
  #&lt;struct-type blank&gt;
  2&gt; (pprof (new blank))
  malloc bytes:            16
  gc heap bytes:           32
  total:                   48
  milliseconds:             0
  #S(blank)
</code></pre>
32 bit:<p><pre><code>  2&gt; (pprof (new blank))
  malloc bytes:             8
  gc heap bytes:           16
  total:                   24
  milliseconds:             0
  #S(blank)
</code></pre>
The structure instance has a pointer to its type, followed by a numeric ID (which is also in the type, but is forwarded to the instance for faster access). The ID is combined with a slot symbol to perform a cache lookup to get the offset of a slot.  The numeric ID is a fixnum, which leaves a few spare bits for a couple of flags:<p><pre><code>  struct struct_inst {                                                            
    struct struct_type *type;                                                     
    cnum id : sizeof (cnum) * CHAR_BIT - TAG_SHIFT;                               
    unsigned lazy : 1;                                                            
    unsigned dirty : 1;                                                           
    val slot[1];                                                                  
  };                                                                              
</code></pre>
If someone wanted to shrink this, they could patch the code so that the dirty flag support, and lazy instantiation of structs is made optional (as in compiled out), and so is the forwarding of the inst-&gt;type-&gt;id to inst-&gt;id. This struct type is not known outside of struct.c, which is only some 1700 lines long. If you take out the id member from struct_inst, the C compiler will find all the places that have to be fixed up; literally a 15 minute job.<p>I can also think of a more substantial refactoring that would eliminate the type pointer also. There is no room in the heap object handle to store it directly: heap handles have four words in them; the COBJ ones used for structs have the type field, a class symbol, a pointer to an operations structure, and a pointer to some associated object (in this case struct_inst). All structures share the same operations structure. However, if we dynamically allocate that operations structure for each struct <i>type</i>, we could stick the type pointer in there, taking it out of the instance. Thus an instance size could literally just be sizeof(pointer) * no-of-instance-slots.