Home > Uncategorized > More compact format for Java classes

More compact format for Java classes

I’ve noticed that compiled Java code takes more place then source code. For example, a simple equation solver written by me takes 15 kbytes in source and 30 kbytes in compiled form. Source code is archived to 3 kbytes, and compiled code  to 17 kbytes. Since I have written a library for reading and manipulating .class files, I’ve decided to find out why these files are so big.

For equation solver I have following results: contstant pool takes 61% of total space, and methods take 32%. So, majority of space is taken by constants. Maybe this could be optimized? There are several types of constants which contain references to other constants. These are MethodReference, ClassReference, StringReference, FieldReference, NameTypePair. Each reference takes two bytes. My program is composed of small classes, with typical constant pools consisting of 50-80 entries. So, for such classes it is possible to store references using only one byte. I’ve invented a new file format, named “slass”, which uses such technique for saving space, and implemented it in my library. Testing with abovementioned equation solver gives 7% improvement on size of constant pool, which makes a 4% improvement on size of .class file! No, it was not worth inventing.

Categories: Uncategorized
  1. May 8, 2017 at 6:49 am

    I love this post wow! I read your blog often and you are very
    inspiring. I shared this on my page and all my followers loved it!
    Keep it up

  2. June 4, 2017 at 6:10 pm

    Good ⅾay I am so excited I found yopur webpage, I гeally found you by mistake,
    whilke I wаs looking on Google for something else, Nonethelrss I
    am here now and would just like to say thank you for
    a tremendous post and a all round eҳciting blog (I alsso love the thеme/design), I
    don’t have time to go through it all at
    the minute but I have Ƅook-marked it and also included your RSS feeds,
    so when I haνe tme I will be back to read a greɑt deql more, Please do keep up thᥱ greatt b.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: