Improving clojure.jar/clojure-contrib.jar compression (ClassLoader alternatives)

20 views
Skip to first unread message

Dimiter "malkia" Stanev

unread,
Apr 17, 2009, 7:36:24 PM4/17/09
to Clojure
I'm asking here question not directly related to Clojure, but related
to the JVM:

Is there any alternative (ClassLoader?) to store the .class files in a
different compressed format?.NET can store lots of classes in one
assembly? Is there something like that for JVM?

For example right now clojure.jar is 1.5MB, but that's because JAR
(which is ZIP based) is inefficient when storing lots of small
(.class) files. Instead a solid archive (.tar.gz) is more efficient.
The size goes to 0.5MB when compressed like that.

Same for clojure-contrib.jar - from 2mb .jar goes down to 1mb .tar.gz
- so instead of 3.5mb it goes down to 1.5MB in total.

Anyone has an insight (I myself am Java newbie), but I'm concerned
with the size of it.


Stuart Sierra

unread,
Apr 17, 2009, 10:37:03 PM4/17/09
to Clojure
On Apr 17, 7:36 pm, "Dimiter \"malkia\" Stanev" <mal...@gmail.com>
wrote:
> Is there any alternative (ClassLoader?) to store the .class files in a
> different compressed format?.NET can store lots of classes in one
> assembly? Is there something like that for JVM?

ClassLoaders can do almost anything, including load classes via HTTP,
so I expect it would be possible to write a custom ClassLoader that
uses a different compression format (like tar.gz). But it wouldn't
necessarily be easy. ZIP is convenient because it permits random
access to any file within the archive, which tar does not.

Here's an (old) article with a related example:
http://www.javaworld.com/javaworld/jw-04-2000/jw-0421-zipclass.html

-Stuart Sierra

kevin

unread,
Apr 18, 2009, 12:22:39 PM4/18/09
to Clojure
You can use java's pack200 tool to compress your jar down quite a bit:

http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/pack200.html

I haven't tried it yet, but this ClassLoader that will decompress the
pack200 archive into a temp directory before loading the classes.

http://scala.sygneca.com/code/compressed-executable-jar

Kevin
Reply all
Reply to author
Forward
0 new messages