Fork me on GitHub
#graalvm
<
2022-11-25
>
wombawomba13:11:33

I'm looking to create a minimal statically linked (using musl) native-image Clojure build. My one-liner hello world app with zero dependencies currently weighs in at 17 MB (5MB with UPX). How can I shrink it more?

ericdallo13:11:20

@U04V15CAJ is expert on doing that

wombawomba13:11:44

(I'm including --enable-http here because I'll need it eventually – without that flag the resulting build is 13MB)

ericdallo13:11:51

Since it's just a hello world, probably there is nothing that much to improve on clojure side

ericdallo13:11:43

https://github.com/borkdude/dynaload may be a good lib to consider depending on how much your code increase

wombawomba13:11:44

(and -Dclojure.compiler.direct-linking=true)

wombawomba13:11:03

yeah, thanks

borkdude13:11:37

I think this is about the size you can expect from a clojure based image

ericdallo13:11:42

clojure-lsp adds

-H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.AudioFileReader \
     -H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiFileReader \
     -H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.MixerProvider \
     -H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.FormatConversionProvider \
     -H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.AudioFileWriter \
     -H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiDeviceProvider \
     -H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.SoundbankReader \
     -H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiFileWriter
to remove some unused stuff, but TBH I don't remember if that is worth/if affects that much the size

borkdude13:11:49

I think that was copied from bb

borkdude13:11:54

and is probably not necessary

👍 1
wombawomba13:11:03

yeah, doesn't seem to make a difference

wombawomba13:11:20

guess I'll write this thing in Rust instead 🙂

borkdude13:11:47

what kind of thing is it?

wombawomba13:11:58

a utility that I'm packaging as a container, and that I need to be as small as possible to reduce latency when downloading it

borkdude13:11:24

is 10mb going to make a difference? zipped 5mb?

borkdude13:11:46

babashka installs in 0s on github actions and it's 25mb zipped or so (75 unzipped)

borkdude13:11:12

a reduction in size with upx doesn't even outweigh the smaller download, since the download is already zipped

borkdude13:11:26

and upx adds to the start time since it unzips the binary on every startup

☝️ 1
lispyclouds13:11:10

Is this something that is intended to be run as a lambda?

holy-lambda 2
borkdude13:11:29

you can also write lambdas with #C029PTWD3HR - just a couple of lines

borkdude13:11:08

They just have a new Node 18 runner. ARM runners are the fastest especially when you choose more memory

wombawomba13:11:42

it's for something more like a backend for running lambdas

wombawomba13:11:34

every MB counts

👍 1
wombawomba13:11:28

I could make sure to load it upfront of course, in which case it wouldn't be that big a deal

borkdude13:11:30

yeah in that case rust or go might make sense

lispyclouds13:11:32

if its the download latency youre worried about, id go with #nbb or layer in the binary in the runtime

wombawomba13:11:35

but might as well go for smaller size so I can download it when I need it

borkdude13:11:34

or ... zig! :)

wombawomba13:11:31

thanks! 🙂

rmxm15:12:04

Also I think now you can also have ram loaded preemptively into AWS Lambda, so that startup time can become really minimal. I have not checked it out, but https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html?icmpid=docs_lambda_rss

djhaskin98718:01:07

There's also tools that compress your exe and decompress and run them at runtime, like UPX and gzexe https://upx.github.io/ https://linux.die.net/man/1/gzexe

borkdude19:01:42

I'm aware of those tools but they affect startup time negatively

borkdude19:01:59

FWIW, upx was mentioned in the original message of this thread