title: How to estimate the serialization size of objects in Java without actually serializing them?
body: <p>To enhance messaging in a cluster, it's important to know at runtime about how big a message is (should I prefer processing local or remote).</p>
  
  <p>I could just find frameworks about estimating the object memory size based on java instrumentation. I've tested classmexer, which didn't come close to the serialization size and sourceforge SizeOf. </p>
  
  <p>In a small testcase, SizeOf was around 10% wrong and 10x faster than serialization. (Still transient breaks the estimation completely and since e.g. ArrayList is transient but is serialized as an Array, it's not easy to patch SizeOf. But I could live with that)</p>
  
  <p>On the other hand, 10x faster with 10% error doesn't seem very good. Any ideas how I could do better?</p>
  
  <p>Update: I also tested ObjectSize (<a href="http://sourceforge.net/projects/objectsize-java" rel="nofollow noreferrer">http://sourceforge.net/projects/objectsize-java</a>). Results seem just good for non-inheritating objects :(</p>