JAR size and class

Started by
3 comments, last by Graylien 19 years, 10 months ago
Hi all, I would like to know which one is better: having small number of big classes, or having big number of small classes, to get minimum JAR size. Thanks a lot.
Advertisement
A small number of big classes. JAR compression is done on a per file basis, it can''t compress across different files. So bigger files allow for higher compression rates. Also, there are less header entries in the jar describing the files.

shmoove
to be more specific:

- a file entry in .jar takes somewhere around 100bytes (i think it takes 94bytes)
- a class takes at least 150bytes just because it is a class ( i suppose it''s the code for constructors and class identification information)

when i started to optimize some game for size, i was expecting to reduce reduced_classes_number * 200 bytes, but the reality was that i obtained somewhere around reduced_classes_number * 300 or even more by merging classes.
Merging classes also sometimes allows you to make other savings by doing the dispatch manually, inlining stuff etc. Just random little things that you can't really predict, but you'll find if you look for them. The overhead of some design patterns can be surprisingly large.

That said, design your code nicely first and optimize it later.
Quote:Original post by Zahlman
That said, design your code nicely first and optimize it later.


Design your code nicely, get it to work properly, and optimize it later.

Or, as Knuth put it, "premature optimization is the root of all evil."
------When thirsty for life, drink whisky. When thirsty for water, add ice.

This topic is closed to new replies.

Advertisement