Can executable size be optimized?
Asked Answered
M

1

6

I have created executable of following code in Racket (choosing Racket and not GRacket):

#lang racket
(print "Hello World!")

It creates a tgz of 3.6 mb with an executable of 6.2 mb. This seems very large for this simplest program. Executable created by Chicken Scheme with same code (print "Hello World!") is of size 16984 bytes (16.6 kb) only.

I think I am missing something (possibly some optimization setting) while creating executable in Racket. How can this executable be made smaller?

Minelayer answered 9/4, 2017 at 13:59 Comment(0)
S
8

The documentation for raco exe recommends using as small a base language as possible. In this case, replace #lang racket with #lang racket/base. On my machine (Linux, Racket 6.8) that drops the executable size from 6.6M to 988K.

I was able to further reduce the size of the executable by running the demodularizer first. I saved the program as hello.rkt and ran

$ raco demod hello.rkt
$ raco exe -o hello hello_rkt_merged.zo

That produces an executable of 277K.

Suspire answered 10/4, 2017 at 6:26 Comment(3)
This solution used to work, but it doesn't anymore on the newer Racket 7.0Ignominy
@Ignominy thanks, I've created a bug report here: github.com/racket/racket/issues/2226Suspire
I tried to build it today with DrRacket 8.11[cs] on MacOS (Sonoma 14.1.1) and ended up having the size of 48 MB. I noticed that the size of the 'racket' executable itself is about the same size (not sure whether it is related - just find it suspicious).Probity

© 2022 - 2024 — McMap. All rights reserved.