Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

jar fat

8 views
Skip to first unread message

Roedy Green

unread,
Apr 14, 2012, 5:39:32 AM4/14/12
to
It coming clear to me the astounding amount of junk that gets carried
around in jars. If you just even one method of a class, that whole
class gets included. Then every class that class references
recursively is included, if even you never use that code.

At least a class is not loaded unless it is used, but if even one
constant out of it is used, the whole class gets loaded.

Its a good thing RAM prices have dropped so drastically.
--
Roedy Green Canadian Mind Products
http://mindprod.com
When you were a child, if you did your own experiment
to see if it was better to put to cocoa into your cup first
or the hot milk first, then you likely have the programmer gene..

Casey Hawthorne

unread,
Apr 15, 2012, 1:13:55 AM4/15/12
to
On Sat, 14 Apr 2012 02:39:32 -0700, Roedy Green
<see_w...@mindprod.com.invalid> wrote:

>It coming clear to me the astounding amount of junk that gets carried
>around in jars. If you just even one method of a class, that whole
>class gets included. Then every class that class references
>recursively is included, if even you never use that code.
>
>At least a class is not loaded unless it is used, but if even one
>constant out of it is used, the whole class gets loaded.
>
>Its a good thing RAM prices have dropped so drastically.

I had thought that the Java compiler was smarter than this and would
just include the used method(s) and the constructor(s).

That is, I thought that the Java compiler was better at figuring out
dependencies; it's no wonder other JVM languages are catching on.
--
Regards,
Casey

Fredrik Jonson

unread,
Apr 15, 2012, 3:49:22 AM4/15/12
to
In <j8hio7hve9i127gi6...@4ax.com> Roedy Green wrote:

> It coming clear to me the astounding amount of junk that gets carried
> around in jars.

There's nothing stopping you from using a optimizer, like Proguard, to
inline methods, variables, and even merge classes. If you use Maven you
can also use the shade plugin to merge jars, and include only the classes
you really use from your dependencies.

One disadvantage is that you wont get a stacktrace that reflect your
code unless you postprocess the staktrace. You also need to be mindful
of code that use reflection as the optimized code normally does not
keep the original class and method names.

Using proguard is normal for systems that needs it, like Android and
Java ME. I have a hard time imagining a current day desktop or server
system where a couple of megabytes of additional jar files atually
matters very much.

Still I can agree that there is a problem here. One of my objections
to using Spring is that the war-files quickly grow very large due
to dependenies. A web app easily grow to somewhere between 15 to 25
megabytes when you use Spring and some persistence framework, like
hibernate, which admittedly also adds quite a lot. Event with fast
networks and huge disks it bothers me having to lug around copies
of all that framework junk in every webapp I have to build.

--
Fredrik Jonson

Fredrik Jonson

unread,
Apr 15, 2012, 4:14:27 AM4/15/12
to
In <34mko7t53h5ncp3fc...@4ax.com> Casey Hawthorne wrote:

> I had thought that the Java compiler was smarter than this and would
> just include the used methods and the constructors.

No, the compiler only does very limited optimizations, like dead code
elimination and inlining of constants. What you do get with java is inline
expansion of the methods during runtime execution, when the jvm identifies
it as hot spot. Basically, you could say that the system - compiler and
runtime - wont optimize until it can identify a runtime advantage.

> That is, I thought that the Java compiler was better at figuring out
> dependencies; it's no wonder other JVM languages are catching on.

Do you really believe that other JVM languages are gaining interest
due to being better att optimizing class files? I'd think that is pretty
far down the list of features that makes you choose to swith from java to
another JVM language.

--
Fredrik Jonson

Roedy Green

unread,
May 26, 2012, 4:36:54 AM5/26/12
to
On Sat, 14 Apr 2012 22:13:55 -0700, Casey Hawthorne
<caseyhHA...@istar.ca> wrote, quoted or indirectly quoted
someone who said :

>
>I had thought that the Java compiler was smarter than this and would
>just include the used method(s) and the constructor(s).

It can't be that smart. To know what's needed requires seeing all the
referrers, i.e. the entire jar. And further, you might dynamically
load something that uses some of the rare methods.

Jet has various ways of chewing on this problem. Sometimes you run
the program and it monitors what extra stuff you dynamically load.
--
Roedy Green Canadian Mind Products
http://mindprod.com
I would be quite surprised if the NSA (National Security Agency)
did not have a computer program to scan bits of shredded
documents and electronically put them back together like a giant
jigsaw puzzle. This suggests you cannot just shred, you must also burn.
.
0 new messages