From: Xuan B. <med...@us...> - 2008-06-22 11:02:00
|
Update of /cvsroot/tm4j/tm4j/src/org/tm4j/topicmap/tmdm/merged In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv16378/src/org/tm4j/topicmap/tmdm/merged Modified Files: MergedAssociationKey.java Log Message: Memory consumption analysis for MergedAssociationKeys. Index: MergedAssociationKey.java =================================================================== RCS file: /cvsroot/tm4j/tm4j/src/org/tm4j/topicmap/tmdm/merged/MergedAssociationKey.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MergedAssociationKey.java 19 Jun 2008 11:25:11 -0000 1.2 --- MergedAssociationKey.java 21 Jun 2008 16:26:04 -0000 1.3 *************** *** 23,33 **** This object consumes on 64-bit machines, on average, ! (2*8+8+8+8+8)+ (MergedAssociationKey: object header + 1 inherited pointer + 2 pointers + 1 int + alignment) ! (2*8+8)+ (HashSet: object header + 1 pointer) ! (2*8+6*8)+ (HashMap: object header + content) ! (3*8+16*8)+ (HashMap.table: object header + content (default table size)) ! (2*8+4*8)*2+ (HashMap.Entry: object header + content) 2 times (because, typically, associations have 2 roles) ! (2*8+8+8)*2 (MergedAssociationRoleKey: object header + type + player) 2 times (because, typically, associations have 2 roles) = 448 bytes. */ protected MergedTopic type; --- 23,50 ---- This object consumes on 64-bit machines, on average, ! (2*8+8+8+8+8)+ (MergedAssociationKey: object header + 1 inherited pointer + 2 pointers + 1 int + alignment) ! (2*8+8)+ (HashSet: object header + 1 pointer) ! (2*8+6*8)+ (HashMap: object header + content) ! (3*8+16*8)+ (HashMap.table: object header + content (default table size)) ! (2*8+4*8)*2+ (HashMap.Entry: object header + content) 2 times (because, typically, associations have 2 roles) ! (2*8+8+8)*2 (MergedAssociationRoleKey: object header + type + player) 2 times (because, typically, associations have 2 roles) = 448 bytes. + + We should consider an optimization: + + (2*8+8+8+8+8)+ (MergedAssociationKey: object header + 1 inherited pointer + 2 pointers + 1 int + alignment) + (3*8+2*8*n) (compressed roles array: object header + array consisting of pointer to role,player,role,player,role,player,... ) n times (for n roles) + = 72+16*n bytes. (=104 bytes for a binary association). + + Maybe we should even specialize the association key for binary and ternary associations (because these are the most common ones): + + (2*8+8+8+8+8+2*16) (MergedBinaryAssociationKey: object header + 1 inherited pointer + 2 pointers + 1 int + alignment + role,player,role,player) + = 80 bytes (a memory saving of factor 5.6) + + (2*8+8+8+8+8+3*16) (MergedTernaryAssociationKey: object header + 1 inherited pointer + 2 pointers + 1 int + alignment + role,player,role,player,role,player) + = 96 bytes (a memory saving of factor 4.6) + + At this stage, we should even evaluate whether cacheing the hashCode makes sense, as the hashCode is already cached in java.util.HashMap$Entry. + If we kill the hashCode, we improve by another 8 bytes (because we do not need alignment anymore), saving another 10% for MergedBinaryAssociationKey. */ protected MergedTopic type; |