Bug 312839 - reduce class file size
Summary: reduce class file size
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.6.9M2   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: 1.6.9   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-13 16:36 EDT by Andrew Clement CLA
Modified: 2010-05-19 11:23 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Clement CLA 2010-05-13 16:36:09 EDT
Now ITDs are becoming fashionable we should take more care about class file sizes.  I've just built the standard Roo petclinic with 1.6.9m2, the file Pet.class is 27,417bytes, the WeaverState attribute inside is 0x38BDbytes (14525bytes).

There is a lot of duplication in there, not only is that attribute used to record the reweavable diff, it records which aspects are affecting the type, which mungers are affecting the type - and in all these cases writes out the bytes for the string signatures of any types.  It should be using the constant pool which is likely to already have these strings in.
Comment 1 Andrew Clement CLA 2010-05-13 16:38:55 EDT
the list of aspects in affect will need to switch to the slashed internal form (from dotted form) so that constant pool entries can be shared.
Comment 2 Andrew Clement CLA 2010-05-13 16:41:57 EDT
Here are some rough string numbers.  This is the Pet class in petclinic.  There are 31 type mungers in affect and all of them are prefixed by the owning aspect (all these strings already exist in the constant pool):

Writing out Lcom/springsource/petclinic/domain/Pet_Roo_ToString;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Finder;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Finder;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Finder;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Finder;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_JavaBean;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_JavaBean;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_JavaBean;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_JavaBean;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_JavaBean;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_JavaBean;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_JavaBean;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_JavaBean;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_JavaBean;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_JavaBean;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;
Writing out Lcom/springsource/petclinic/domain/Pet_Roo_Entity;

Then the aspects affecting the type are written out. All these strings already exist in slashed form in the constantpool:

aspect affecting type com.springsource.petclinic.domain.Pet_Roo_Entity
aspect affecting type com.springsource.petclinic.domain.Pet_Roo_ToString
aspect affecting type com.springsource.petclinic.domain.Pet_Roo_Configurable
aspect affecting type org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect
aspect affecting type com.springsource.petclinic.domain.Pet_Roo_JavaBean
aspect affecting type com.springsource.petclinic.domain.Pet_Roo_Finder
Comment 3 Andrew Clement CLA 2010-05-14 00:31:54 EDT
Working on a simple class with a couple of methods in that is affected by a pair of ITDs.  Here are the numbers and what I've done for each reduction:

// 2531 (0x404): 1.6.9.M2 size of Class.class
// 2494 (0x3DF): first little stab, compressing aspectnames attached to type mungers
// 2370 (0x363): changed read/write sourcelocation to write path rather than File object
// 2358 (0x357): aspects affecting type compressed (weaverstate reweavable info)
// 2102 (0x257): changed read/write sourcelocation in type munger to NOT use object streams
// 2053 (0x1EF): changed path in sourcelocation read/write to be constant pool (so shared between both mungers)

20% reduction on that simple class with just those few tweaks.  WeaverStateInfo is 50% the size it was previously.  These savings won't quite scale linearly as the class file size grows, but should make a dent in the size of a huge class.

Another comparison number to use Petclinic Roo built with 1.6.9m2 is a total of 335,456 bytes - that is 'dir *.class /s' run in target/classes.

Other obverservations: munger sizes are still quite large, appears to be the poor job of serialization done in ResolvedMember
Comment 4 Andrew Clement CLA 2010-05-14 11:57:27 EDT
that size for PetClinic in the previous comment possibly didn't include the build tests.  Today the changes so far are merged into something that can build petclinic.  Comparisons:

All .class bytes in petclinic:
169m2: 698,060
169dev:649,322

Targetted files:
Pet: was 27417 now 17853
Visit: was 25522 now 16810
Owner: was 8645 now 6662

There are some very large classes remaining though, like PetController_Roo_Controller (was 58580 now 58547)
Comment 5 Andrew Clement CLA 2010-05-14 16:02:29 EDT
Gone a bit further.  Allowed constant pool usage during the compile stage, not just the weave stage (enables compilation to compress data too).

Also compressing ResolvedMemberImpl.

Pet: was 27417 now 17853, now 15372
Visit: was 25522 now 16810, now 14533
Owner: was 8645 now 6662, now 6052

PetController_Roo_Controller: was 58580 now 58547, now 30,260 (!)

total petclinic now down to 423,888 (from 698,060) - huge drop of 270k.
Comment 6 Andrew Clement CLA 2010-05-19 11:23:20 EDT
all changes are in, notes:

Post 1.6.9m2 changes to serialization format for WeaverStateInfo:

1) a boolean is included ahead of the (length:typemungers) data that indicates if the data following it is compressed.
2) when the typeMungers are written out, the defining aspects for them are compressed into cp entries.
3) when the reweavable data is written out, the signatures of the aspects affecting the type are compressed

MISSING types being written/read
aspectsaffectingtype made into signatures rather than dotted names

ResolvedTypeMunger:
writeSuperMethodsCalled: count reduced to byte from int
writeSourceLocation: changed from object stream writing to proper serialization
typeAliases: length to byte

SourceContextAttribute: instead of multiple ints, now diffs stored for each line (saves 2bytes * number of lines in the source file)
ExactTypePattern - writes out type as cp ref
TypePatternlist - doesn't record source location (it was meaningless)

---- 

final numbers.  This time I'm compiling all of the petclinic app including the tests with 'mvn clean compile test'

this creates 62 class files.  Total space is 1,033,516bytes.  Pet is 27417bytes and Pet Entity aspect is 45254bytes.

With the changes in this bugzilla.  Total space is 632,026 (~40% smaller).  Pet is 15183bytes Pet Entity aspect is 26908cal