Recent

Author Topic: Why are the generated binaries so big?  (Read 15650 times)

LazaruX

  • Hero Member
  • *****
  • Posts: 597
  • Lazarus original cheetah.The cheetah doesn't cheat
Why are the generated binaries so big?
« on: February 02, 2009, 11:22:43 am »
Hi everybody,
Since the forum become faster in the last weeks, I have seen a lot of newbies in the forum, and again, in months I always see the same question again. Something I also wondered myself in the beginning. But for those that are in the forum a bit longer than the newbies, reading always the same question is a bit frustrating:

In Lazarus, the executable are larger than Delphi and this is normal:

http://wiki.lazarus.freepascal.org/Lazarus_Faq#Why_are_the_generated_binaries_so_big.3F

You can use STRIP to remove the debugging information and make the .EXE smaller.

You can use UPX or other executables compressors to reduce even more its size.

Please read the FAQ's.

Thanks
« Last Edit: February 02, 2009, 12:21:32 pm by BPsoftware »

FangQ

  • Full Member
  • ***
  • Posts: 134
Re: Why are the generated binaries so big?
« Reply #1 on: May 07, 2009, 07:49:47 pm »
I ran Lazarus 0.9.26-4 on my Ubuntu desktop and now am working on a simple GUI. The compiled binary file is 16M. After reading the FAQ, I turned on the -Xs option from Project\Compiler options\Linking, and rebuilt the project, the binary is still 16M in size!

I quit the project, and restarted lazarus, after reloading the project, I verified the -Xs flag was on, and a recompilation still made no difference in the binary file size.

My code is only less than 100 lines, which you can find it at
http://forum.lazarus.freepascal.org/index.php/topic,6693.msg31294.html#new

does this sound like a bug or something I missed?

Troodon

  • Sr. Member
  • ****
  • Posts: 484
Re: Why are the generated binaries so big?
« Reply #2 on: May 07, 2009, 09:05:47 pm »
1. Project|Compiler Options|Code|Smart Linkable (-CX) -> Checked
2. Project|Compiler Options|Linking|Debugging|Display Line Numbers in Run-time ErrorBacktraces (-gl) -> Unchecked
3. Project|Compiler Options|Linking|Debugging|Strip Symbols From Executable (-Xs) -> Checked
4. Project|Compiler Options|Linking|Link Style|Link Smart (-XX) -> Checked

The most important seem to be 2 and 3. The executable size should be now 2-3 MB instead of 16 MB.

5. Run upx <your_executable> to compress your binary by a factor of 2-3.

You can also try (before using upx), but that might decrease performance: Project|Compiler Options|Code|Optimizations|smaller rather than faster -> Checked
« Last Edit: May 08, 2009, 05:22:49 pm by Troodon »
Lazarus/FPC on Linux

FangQ

  • Full Member
  • ***
  • Posts: 134
Re: Why are the generated binaries so big?
« Reply #3 on: May 07, 2009, 10:58:45 pm »
1. Project|Compiler Options|Code| Smart Linkable (-CX) -> Checked
2. Project|Compiler Options|Linking|Debugging|Display Line Numbers in Run-time ErrorBacktraces (-gl) -> Unchecked
3. Project|Compiler Options|Linking|Debugging|Strip Symbols From Executable (-Xs) -> Checked
4. Project|Compiler Options|Linking|Link Style|Link Smart (-XX) -> Checked

The most important seem to be 2 and 3. The executable size should be now 2-3 MB instead of 16 MB.

5. Run upx <your_executable> to compress your binary by a factor of 2-3.

thank you, what you mentioned indeed did the trick.

items 2 and 3 cut one of my program from 24M down to 4M, 1 and 4 further reduce it to 3.3M. I am happy with this size.

TurboRascal

  • Hero Member
  • *****
  • Posts: 672
  • "Good sysadmin. Bad programmer."™
Re: Why are the generated binaries so big?
« Reply #4 on: October 28, 2009, 06:20:05 pm »
2. Project|Compiler Options|Linking|Debugging|Display Line Numbers in Run-time ErrorBacktraces (-gl) -> Unchecked

This is the only option that made a difference for me, and is really worth it, saving 10 megs or more.  I wonder if the Smart Linking works at all? I see no difference, and minimum executable size is 1.8M for me (empty project) and quickly rises to several megs by including more components/units...

Btw. using the -Xg option, it saves debug data to another file, also leaving the executable lean.

5. Run upx <your_executable> to compress your binary by a factor of 2-3.

I wouldn't want to use UPX at all because it interferes with proper memory mapping of executables, increasing load time and memory consumption. Only if I'd really need to cram the program onto a floppy or an embedded controller or something...
Regards, ArNy the Turbo Rascal
-
"The secret is to give them what they need, not what they want." - Scotty, STTNG:Relics

alter

  • Full Member
  • ***
  • Posts: 151
    • KSP website
Re: Why are the generated binaries so big?
« Reply #5 on: October 28, 2009, 07:06:45 pm »
2. Project|Compiler Options|Linking|Debugging|Display Line Numbers in Run-time ErrorBacktraces (-gl) -> Unchecked

This is the only option that made a difference for me, and is really worth it, saving 10 megs or more.  I wonder if the Smart Linking works at all? I see no difference, and minimum executable size is 1.8M for me (empty project) and quickly rises to several megs by including more components/units...

Btw. using the -Xg option, it saves debug data to another file, also leaving the executable lean.

5. Run upx <your_executable> to compress your binary by a factor of 2-3.

I wouldn't want to use UPX at all because it interferes with proper memory mapping of executables, increasing load time and memory consumption. Only if I'd really need to cram the program onto a floppy or an embedded controller or something...
Application size 50 mb just because it uses Qt (need version for Linux too, win32 components in Lazarus are not enough and OLE support isn't still that good so Qt is the best solution). Using Qt saves time since many parts of program I have to write only once but increases hdd requirements to 50 mb. As for application that is either started once in a while (runs in background) or simply used once in a while even 100 RAM consumption isn't still that bad (on Windows 7 x64, total RAM available is 4 GB). The biggest problem might be increased startup time. So sometimes it is worth especially if hdd requirement drops from 50 to 15 or even less.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Why are the generated binaries so big?
« Reply #6 on: October 29, 2009, 03:10:38 pm »
My experience:
Project:
Lazarus 0.9.29, Kubuntu 64bit, Qt 4.5
more than 10.000 lines,
more than 500 components on form (including menu items)
Compliled binary 12.1MB, after strip 4.8MB, after upx 1.2MB.
When executed, System Monitor shows 14.4MB allocated memory and 23.1MB of shared memory.
Executing is very fast, I click in File Manager (Krusader) and binary is started in one second.
Some time ago in Windows (32bit Vista) was binaries even little smaller, about 500kb after strip and upx, but I added many lines and components.
When I compile my project with GTK2, binary is about 14MB and 1.4MB after strip+upx.
When I add new code and components, final size is growing very slowly.
I think it's very good.
B.

 
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

LazaruX

  • Hero Member
  • *****
  • Posts: 597
  • Lazarus original cheetah.The cheetah doesn't cheat
Re: Why are the generated binaries so big?
« Reply #7 on: October 29, 2009, 04:43:52 pm »
Well, for a 10.000 lines code, 1.4 MB is good I think,

alter

  • Full Member
  • ***
  • Posts: 151
    • KSP website
Re: Why are the generated binaries so big?
« Reply #8 on: October 29, 2009, 07:17:23 pm »
Didn't count all lines nor components:-) Definitely main form has around 150 components, total code (including 3rd party libraries not delivered with Lazarus) around 90 000 lines. exe size 3.51 MB without upx, with upx it is 946 KB (LZMA). Windows compilation.

 

TinyPortal © 2005-2018