graalvm

wombawomba 2022-11-25T13:36:33.410139Z

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?

ericdallo 2022-11-25T13:39:20.888109Z

@borkdude is expert on doing that

wombawomba 2022-11-25T13:39:44.058489Z

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

ericdallo 2022-11-25T13:39:51.626999Z

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

wombawomba 2022-11-25T13:41:19.829609Z

(oh and I'm using https://github.com/clj-easy/graal-build-time)

ericdallo 2022-11-25T13:41:43.012359Z

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

wombawomba 2022-11-25T13:41:44.864669Z

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

wombawomba 2022-11-25T13:42:03.779029Z

yeah, thanks

borkdude 2022-11-25T13:42:37.222459Z

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

ericdallo 2022-11-25T13:42:42.223999Z

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

wombawomba 2022-11-25T13:43:31.322549Z

hmm okay

borkdude 2022-11-25T13:43:49.391039Z

I think that was copied from bb

borkdude 2022-11-25T13:43:54.292739Z

and is probably not necessary

👍 1
wombawomba 2022-11-25T13:45:03.272929Z

yeah, doesn't seem to make a difference

wombawomba 2022-11-25T13:45:20.688899Z

guess I'll write this thing in Rust instead 🙂

borkdude 2022-11-25T13:46:47.776719Z

what kind of thing is it?

wombawomba 2022-11-25T13:47:58.106159Z

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

borkdude 2022-11-25T13:48:24.768239Z

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

borkdude 2022-11-25T13:48:46.949769Z

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

borkdude 2022-11-25T13:50:12.319309Z

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

borkdude 2022-11-25T13:50:26.710729Z

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

☝️ 1
lispyclouds 2022-11-25T13:51:10.484809Z

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

2
borkdude 2022-11-25T13:52:29.350169Z

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

borkdude 2022-11-25T13:52:41.523729Z

https://www.juxt.pro/blog/nbb-lambda

borkdude 2022-11-25T13:53:08.836159Z

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

wombawomba 2022-11-25T13:54:42.074269Z

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

wombawomba 2022-11-25T13:55:34.107949Z

every MB counts

👍 1
wombawomba 2022-11-25T13:56:28.478859Z

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

borkdude 2022-11-25T13:56:30.775519Z

yeah in that case rust or go might make sense

lispyclouds 2022-11-25T13:56:32.137199Z

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

wombawomba 2022-11-25T13:56:35.712529Z

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

borkdude 2022-11-25T13:57:34.946329Z

or ... zig! :)

lispyclouds 2022-11-25T13:57:53.549319Z

ive used https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html for fat binaries before

wombawomba 2022-11-25T13:59:31.066009Z

thanks! 🙂

rmxm 2022-12-14T15:40:04.267849Z

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

djhaskin987 2023-01-25T18:38:07.806929Z

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

borkdude 2023-01-25T19:08:42.277809Z

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

borkdude 2023-01-25T19:08:59.784389Z

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