3 ms·
> Single small binaries are easy with go With static linking? I don't think so.
by incepted 10y ago
> Single small binaries are easy with go
With static linking? I don't think so.
- dikaiosune 10y agoCompared to a JAR with many dependencies and no option for LTO?
- pjmlp 10y agoJava 9 brings LTO via jlink.
- mappu 10y agoDoes golang have LTO? (maybe only in gccgo?)
- sievebrain 10y agoYou can make an executable "fat jar" with Capsule. It has a little shell script prepended to the JAR which means you can run it like "chmod +x foo.jar; ./foo.jar" You can do dead code elimination and other forms of LTO using ProGuard. Just watch out for code that uses reflection. Java 9 will include a less aggressive version of the same thing which performs various link time optimisations like deleting modules (rather than individual methods/fields), statically pre-computing various tables, and converting from JAR into a more optimised (but platform specific) format. That tool can also bundle a JRE in with your app, giving you an "tar xzvf and run" deployment model. It's not a single file, but it makes little difference in practice. The same tool can build DEBs, RPMs, Mac DMGs and Windows EXE/MSI installers with a bundled and stripped JRE too.
- dikaiosune 10y agoI'm a big fan of Capsule, actually. My point was not that Java and the JVM ecosystem are terrible (I quite like them), but rather that there is a spectrum of size and complexity and that Go's static binaries seem to be on the simpler to build side of JARs and on the smaller side of JARs. Also, I don't think there's much of a case to be made that bundling a JRE with your JAR is small, even though the tooling might be simple and it might resolve many deployment issues.
- prodigal_erik 10y agoPutting a jar on your classpath works just like depending on a shared library but with much stronger compatibility guarantees and better chances for optimization.
- jsmthrowaway 10y agoYou think wrong. It was the default of the compiler for a long time and only requires minimal work now.