20 ms·
Also worth noting that the JVM itself only weighs a couple of megabytes. The bulk of the size comes from the Java runtime (ie: the "standard libraries"), and th
by gregschlom 10y ago
Also worth noting that the JVM itself only weighs a couple of megabytes. The bulk of the size comes from the Java runtime (ie: the "standard libraries"), and there are lots of things that your app may not need there (XML parsing, serialization, etc...)
A couple of years ago I wrote a simple tool (https://github.com/aerofs/openjdk-trim https://github.com/aerofs/openjdk-trim) that allows you to filter out what you don't need. We were able to get the size of OpenJDK from 100MB down to around 10MB.
Note that the work of determining which classes you need is entirely manual. In our case I used strace to check what classes where being loaded.
- jandrese 10y agoWould it not be possible to scan an app to determine exactly what libraries it could load? I think you can avoid halting problem issues by simply doing a dumb search for the library load routines in the code, at the possible (but not very likely) problem of picking up spurious data in a binary blob section.
- necubi 10y agoThere are tools that do this (for example, proguard). The issue is that java can dynamically load code, so static analysis isn't sufficient. Typically for areas where code size matters (like on Android), you use static analysis plus a manual list.
- necubi 10y agoThis is officially supported in JDK 9. It's part of an ongoing project called "jigsaw" which is introducing modules to the JVM. The first step, shipping in 9, is to modularize the JDK [0]. Already today you can build a custom JDK in the early access release. [0] http://openjdk.java.net/jeps/200 http://openjdk.java.net/jeps/200
- kodablah 10y agoNot that well. The java.base module is still huge. Also, Zulu has nice pre-packaged JDK9 downloads[0] so you don't have to build. 0 - http://zulu.org/zulu-9-pre-release-downloads/ http://zulu.org/zulu-9-pre-release-downloads/
- the8472 10y agoI think jlink can strip at the class level, not just the module level.
- derefr 10y ago> I wrote a simple tool that allows you to filter out what you don't need It'd be a short hop from here to a tool that basically does for JDK-platform apps what Erlang's releases do for the ERTS platform: builds a new JRE (as a portable executable, not an installer) that actually contains the app and its deps in the JRE's stdlib, such that you just end up with a dir containing "a JRE", plus a runtime "boot config" file that tells the JRE what class it should run when you run the JRE executable. With such a setup, your Java program could actually ship as an executable binary, rather than a jar and an instruction to install Java. Nobody would have to know Java's involved! :)
- gregschlom 10y agoFunny you mention that, that's exactly why we wrote this tool. We were having a ton of support issues with our Windows users having to install Java, incompatible Java versions, needing admin privileges to install the JRE, etc... We fixed this whole class of issues by doing exactly what you suggest: bundling the JRE and writing our own launcher binary.
- mirekrusin 10y agoDoes java license interfere with this kind of setup?
- merb 10y agonot when you bundle the openjdk
- jjtheblunt 10y agoIsn't that _exactly_ what GoLang does for its binaries, insofar as shipping them statically linked?
- dvlsg 10y agodotnetcore has it as an option, as well.
- astrodust 10y agoIt would be great to have a runtime for JRuby that's really stripped down to just the necessities. The spin-up time of the jruby environment is painful and it seems predominantly the fault of the JVM's baggage.
- geocar 10y agoI don't know. 10MB still sounds really too big. Why is it so big? What do we gain? I don't have a system with 10MB of cache, so I imagine Java can't run faster than memory...
- guard-of-terra 10y agoLocales? Timezones? Unicode? There's a lot of stuff that is there to be used from time to time, does not mean it hits your processor cache often. BTW, libruby-2.3 is 2,5M, just the shared object file, and it tries to use all aforementioned stuff from the underlying UNIX.
- gregschlom 10y ago10MB for a platform that allows you to run code on all three major operating systems without too much trouble and in a performant way is a huge win, in my opinion. Not many alternatives come close to that.
- pjmlp 10y agoActually all languages with a rich runtime and standard library that isn't just a thin POSIX layer like C or C++ (although C++ has been improving their library story). Still your point holds.
- geocar 10y agoQ/KDB is 600kb, also runs code on all three major operating systems (and a few minor ones). It's also about 1000x faster than Java/Spark[1]. 1000x slower doesn't sound like a huge win to me; it sounds like a huge cost, so my question is what do we gain by making our programs 1000x slower? [1]: http://tech.marksblogg.com/benchmarks.html http://tech.marksblogg.com/benchmarks.html
- adrianN 10y agoThat benchmark is literally comparing Apples to Oranges. It's not even the same hardware.
- 10y ago
- deepsun 10y agoProguard is de-facto standard for Android Java ecosystem, what's the difference OpenJDK-Trim has? Except that Proguard determines used/unused classes automatically, by doing static code analysis, so you need to have proguard config to omit removing stuff that is used dynamically, of course.
- gregschlom 10y agoWe were already using Proguard for obfuscation and we tried to use it to reduce the size of the JDK as well. If my memory serves well the main problem was that the results weren't good enough results because Proguard was being conservative and keeping a lot of stuff that we know we didn't need, but static analysis indicated that it could potentially be used. Also, Proguard's config is pretty complicated and the results are hard to understand. Our approach (openjdk-trim) is dumb simple: unpack the java runtime jars, use rsync to filter out entire directories we don't need, pack it back. It's a simple, brute-force approach compared to Proguard's advanced static analysis, but in this case it gives better results. Maybe a good example of "worse is better".
- aduffy 10y ago-Xverbose:class JVM arg could also have sufficed in case you don't want to use strace.
- ksec 10y agoThat is why i am looking forward and VERY excited for TruffleRuby, SubstrateVM, Graal, along with C Extention. I think once there is official way to trim JDK down, making deployment super easy and fast ( Single executable File ), Java will pick up stream again. The only problem and hesitation we have...is Oracle.
- ominous 10y agoNot to sound rude, but the expression you were aiming to use is maybe "pick up steam". Random example: http://idioms.thefreedictionary.com/pick+up+steam http://idioms.thefreedictionary.com/pick+up+steam
- grw_ 10y agoOT, but this expression seems like a corruption of 'build up steam' and 'pick up speed'. 'Pick up steam' doesn't really make sense in original context- something a steam train would do while stationary and preparing to move :)
- ausjke 10y agoJava8 has profiles already, Java9 will be able to customize further. I'm not a Java guy, but node.js after npm-install the suddenly increased base is hundreds MB easily, I somehow now feel Java/whatever is better organized and manageable. After learning node.js for a product for a few months, I'm actually returning to PHP7, which has nearly identical OOP as Java.
- kazinator 10y agoCouple of megabytes without a run-time is huge. What's hiding in there; a VirtualBox image with a Linux kernel + initrd? Or maybe a high definition splash screen in PNG form?