4 ms·
I just used Jigsaw to create a Java 9 runtime for Windows based on a "Hello World" program. This JRE is only dependent on the 'java.base' module, so it is as s
by MarkMc 10y ago
I just used Jigsaw to create a Java 9 runtime for Windows based on a "Hello World" program. This JRE is only dependent on the 'java.base' module, so it is as small as possible. Yet the resulting JRE is still 35 MB on disk (13.2 MB compressed).
I'm a little disappointed that after so much effort to cut bloat in the JRE, a simple 'Hello World' program still requires 13.2 MB.
- frik 10y agoHow much does a Hello World programm require elsewhere? VB6 1.3MB msvbvm60.dll Java8 150MB C:\Program Files\Java\jre1.8x\ dotNet 250MB C:\Windows\Microsoft.NET\Framework\
- greydius 10y agoC 8.6kb
- verroq 10y agoSince it's dynamically linked against the runtime library most of the time you need to include how big msvcrt*.dll is.
- MBCook 10y agoThat's an unfair comparison, C doesn't have to bundle an entire interpreter.
- Sindisil 10y agoI like,and use, Java, but the fact that the C hello world requires no "interpreter" (JREs almost always also include one or two JIT compilers, and sometimes no interpreter at all) doesn't make the comparison unfair. In fact, it's the point of the comparison. That said, unless the C binary was statically linked against the CRT, the size of the CRT should also be included (at least on Windows).
- MBCook 10y agoRight but the other things in that list were interpreted languages. A purely compiled language is certainly going to be smaller, but that's slightly apples to oranges.
- deleted 10y ago[deleted]
- userbinator 10y agoYou can get <1KB with the appropriate compiler settings. (I am aware that you can get smaller binaries for other languages by changing the compiler settings too, but I doubt any Java binary can reach that size even with the appropriate settings.)
- tokenizerrr 10y agoAnd what are you linking against, then? I can make a tiny .jar file as long as I get to completely ignore the size of the JDK, much like you're ignoring the size of the libraries you're linking against.
- diek 10y agoActually, funnily enough I just went through and built a semi-freestanding exe to load a jlink'd Java 9 JVM: https://gist.github.com/anonymous/cb6e81a36247563d423f36df19e41f9e https://gist.github.com/anonymous/cb6e81a36247563d423f36df19... The only dependencies this particular ex has is on user32.dll and kernel32.dll so it can call LoadLibrary and GetProcAddress, but if I wasn't interacting with those I could remove those dependencies (though then the exe wouldn't be able to do a whole lot of interesting things). If you look at the file in a hex editor, it's mostly just empty space as it just has four 1k sections with a little bit of data at the start of each.
- smitherfield 10y agoI get 8392 bytes on MacOS. $ echo 'main(){puts("hello, world");}' | cc -fno-PIE -m32 -w -xc - && wc -c a.out 8392 a.out (Other code generation and linker options,[1] GCC instead of Clang, different C/C++ standards, printf(3) or write(2) instead of puts(3) and `void main()` instead of `int main()` all had no effect on the binary size). [1] I tried all the ones listed here, although I didn't try the more exotic methods at the end: http://ptspts.blogspot.com/2013/12/how-to-make-smaller-c-and-c-binaries.html http://ptspts.blogspot.com/2013/12/how-to-make-smaller-c-and...
- pythonistic 10y agoGo 1.7: 1.05 MB (statically bundles a stdlib; target Linux, amd64)
- yeahitsmeintmov 10y agoAssembly, 569bytes
- _pmf_ 10y agoAnd you could do that all along using ProGuard on rt.jar (without redistributing it). I remember this being in the 30 MB range, too, so Jigsaw really seems to be utterly useless in reducing the minimum footprint. They could have just allowed vendors to split rt.jar officially.
- kodablah 10y agoIt should be noted that the compressed value is inside a jmod JAR so it doesn't usually need to get decompressed before use I wouldn't think (granted java.exe is buried in there last I checked). Over half of that (21 MB uncompressed) is class files indeed, and those could be trimmed. Another ~40% is native libs (at least on Windows) and surely some of that could be trimmed if unused, granted in Windows the largest is the MSVC runtime. I would expect projects to crop up (I might make one myself) that subdivide java.base even further.