Ran across an interesting tidbit in the new(ish) ART runtime: the object graph traversal algorithm (run as part of the "mark" part of garbage collection) accelerates traversal by storing a four-byte bitmap in each Class. The bitmap marks which of the first 32 fields in the class are objects (as opposed to primitives, which don't need to be traversed). The first field in an object is always a reference to the object's Class, so 31 user-defined fields can fit into the map. What happens if the class has more than 31 fields? Then the runtime has to fall back to finding object fields by reflection. In the current (Android L) version of the runtime, this fallback happens for all
fields, even the first 31.
GC costs in ART affect the application threads less than they did in the old Dalvik runtime, because most of the traversal happens on a separate thread, but there's an unavoidable amount of traversal that has to take place while all app threads are paused. So... yet another reason to avoid monster classes and deep hierarchies, I suppose. ;-) #PERFMATTERS