1. Optimizing size of executable
- Posted by rneu Jun 24, 2017
- 2412 views
For a simplest program:
puts(1, "Hello World!\n")
using compiler command:
euc hello.eu
or:
euc -con hello.eu
I get an executable of size 194 kb. The size is no problem here but may be an issue with larger programs. Are there any options that I can use to optimize the size of executable?
[Just a note: With Chicken Scheme ( https://www.call-cc.org/ ), for a similar simple program, I get an executable sized only 16 kb.]
2. Re: Optimizing size of executable
- Posted by petelomax Jun 25, 2017
- 2298 views
Speaking for Phix rather than Euphoria:
The smallest executable Phix generates is about 220K.
Most of that is from having a full diagnostic system linked in.
The 32-bit compiler is about 2.1MB and the 64-bit compiler is about 3.3MB.
The only thing bigger that I have is Judith's IDE, at about 6.6MB, and that thing is alot of source code.
In Phix/Euphoria when I add ?9/0 I get a proper human readable error message with a filename and source line number, and a full ex.err file.
Can the same be said of Chicken Scheme? [Genuinely asking, I don't know]
Have you any sizes for larger apps in Chicken Scheme?
I would be quite surprised if things continue at a ratio of 15:1
Pete
3. Re: Optimizing size of executable
- Posted by rneu Jun 25, 2017
- 2309 views
I actually have very little experience with Chicken Scheme and I have not tried any larger programs in it. I also do not think detailed error messages are included in it.
For the same simple program, Racket (another Scheme derivative) produces an executable of size 6.2 MB (!), but it can be optimized to 277 KB https://stackoverflow.com/questions/43307580/can-executable-size-be-optimized . (Otherwise, Racket is also a very good language).
I am inclined to compare Euphoria with these Lisp-derived languages since lists (sequences) are key structures in both.
4. Re: Optimizing size of executable
- Posted by Senator Jun 26, 2017
- 2302 views
You can use UPX to compress the executable.
You can write a little Euphoria program or routine to Translate/Compile the source code file and then call UPX to compress the executable. Something like this might work:
-- euc_compress.ex include std/filesys.e sequence cl cl = command_line() if length(cl) >= 3 then ifdef UNIX then cl= cl[3] elsedef cl = lower(cl[3]) end ifdef end if system( "euc " & cl, 0) cl = filebase(cl) system( "upx " & cl, 0)
-- UPX compression of this one line program: -- puts(1, "Hello World!\n") --Build directory: build-720630/ --Translating code, pass: 1 2 3 generating --Compiling with GCC --Compiling 14% init-.c --Compiling 57% hello.c --Compiling 85% main-.c --Linking 100% ../hello --/usr/bin/upx -- Ultimate Packer for eXecutables -- Copyright (C) 1996 - 2013 --UPX 3.91 Markus Oberhumer, Laszlo Molnar & John Reiser Sep 30th 2013 -- -- File size Ratio Format Name -- -------------------- ------ ----------- -- 210152 -> 90360 43.00% linux/ElfAMD hello -- --Packed 1 file. --Hello World! --Press any key...
5. Re: Optimizing size of executable
- Posted by ghaberek (admin) Jun 26, 2017
- 2315 views
Note: I wrote this answer yesterday but apparently forgot to hit Post.
For a simplest program:
puts(1, "Hello World!\n")
using compiler command:
euc hello.eu
or:
euc -con hello.eu
I get an executable of size 194 kb. The size is no problem here but may be an issue with larger programs. Are there any options that I can use to optimize the size of executable?
[Just a note: With Chicken Scheme ( https://www.call-cc.org/ ), for a similar simple program, I get an executable sized only 16 kb.]
Euphoria includes a lot of runtime code into translated executables to implement the required memory management and dynamic object routines. This is going to add some bloat to the executable, but it's helpful and necessary bloat.
There are three ways to reduce the size of an executable:
- Use the GCC "optimize for size" option -Os (the default is -O2)
- Use the GNU strip utility to remove symbols (included with MinGW)
- Use the UPX packer to apply compression (download from UPX)
Here is the program I compiled for this test. I included std/io.e to add some complexity to the program.
-- demo.ex include std/io.e procedure main() puts( STDOUT, "hello, world\n" ) end procedure main()
Here is the command I ran to create a makefile, which I can then edit.
euc -build-dir build -makefile demo.ex
You can compile the executable on Windows like this. On Linux, just specify make.
mingw32-make -j4 -C build -f demo.mak
The line you need to change for -Os is at the top of the makefile:
CFLAGS = -DEWINDOWS -fomit-frame-pointer -c -w -fsigned-char -Os -m32 -IC:/Euphoria -ffast-math ^^
Here are the sizes I got through combining all the options:
Option | Size | Savings |
---|---|---|
-O2 (default) | 362 KB | 0% |
-Os | 350 KB | 3% |
-O2 + strip | 279 KB | 23% |
-Os + strip | 267 KB | 26% |
-O2 + upx | 193 KB | 47% |
-Os + upx | 187 KB | 48% |
-O2 + strip + upx | 110 KB | 70% |
-Os + strip + upx | 104 KB | 71% |
Your mileage may vary with larger executables.
-Greg
6. Re: Optimizing size of executable
- Posted by rneu Jun 26, 2017
- 2261 views
@Senator : UPX Looks like a very useful tool. Thanks.
@Ghaberek : Very clear explanation of different methods of size optimization.
7. Re: Optimizing size of executable
- Posted by _tom (admin) Jun 26, 2017
- 2229 views
Here is an alternative description of how Euphoria works:
Program Sizes
All Euphoria programs have "overhead" that provide features like: safety, type-checks, index-checks, memory management, and garbage collection. These are all desirable features that you get for simply using Euphoria.
This short Euphoria program
puts(1, "Hello Euphoria!" )
is a 28 byte text file; save it as hello.ex". The Interpreter (2.3 MB) will execute this program for you.
eui hello
Interpreting is a two stage process: first source-code is parsed into il-code (intermediate language), second the il-code is interpreted and executed. The .il-code process strips out unused library routines and variables. The Interpreter executes source-code written in plain text which is ideal for program development.
You can save a program as an il-code file and execute it later.
eushroud hello
The result is hello.il**, a 532 byte file, that is no longer human readable.
The il-code is executed by
eub hello
the back-end (eub) is a 2.2 MB file. You can provide users with one eub file and compact "applications" in the form of .il files. A user can neither examine your source-code nor tamper with the .il files.
The binding process will combine a back-end with .il code to make a stand-alone executable:
eubind hello
The result is hello (Unix) or hello.exe (Windows). In this example the executable is 2.3 MB, which is the binder plus the size of the .il code. The advantage of binding is that it is quick and you do not need to install a C-compiler.
You can translate Euphoria source-code into 'C' source-code:
euc -keep hello
You get a folder containing eight files with a total size of 11.9 kb, and hello a stand-alone executable of 210 kb. Execute the application as:
$ ./hello -- Unix # hello -- Windows
When you launch euc without the -keep option the intermediate 'C' files are cleaned up for you.
If you write non-trivial programs the sizes mentioned here grow slowly. The source-code component is actually compact and large programs do not increase in size very much.
_tom
8. Re: Optimizing size of executable
- Posted by Senator Jun 26, 2017
- 2197 views
In my experience, in most instances, an executable file compressed with UPX is actually smaller than a corresponding shrouded *.il file.
1108 wee.il 856 wee -- 23% smaller when Translated/Compiled/packed with UPX 176 euc_compress.il 144 euc_compress -- 18% smaller when Translated/Compiled/packed with UPX
However, shrouding even a program as large as the WEE editor is almost instantaneous whereas the translation/compile/pack cycle takes about 150 seconds on my computer. I think that is very very good.
Regards, Ken