Recent

Author Topic: How to reduce EXE program size?  (Read 26978 times)

alpine

  • Hero Member
  • *****
  • Posts: 1038
Re: How to reduce EXE program size?
« Reply #45 on: April 11, 2021, 08:07:57 pm »
Completely empty Win32 console program:

Delphi7: 14 848 bytes
FPC 3.1.1: 32 768 bytes

No debug info, no RT checking
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: How to reduce EXE program size?
« Reply #46 on: April 11, 2021, 08:21:35 pm »
Completely empty Win32 console program:

Delphi7: 14 848 bytes

NOT UNICODE

Quote
FPC 3.1.1: 32 768 bytes

No debug info, no RT checking

UNICODE.

So to make a fair comparison at least use D2009. We all know that Turbo Pascal 3 also made smaller binaries, but that is not of much use now (unless you compare to the 16-bit dos port)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: How to reduce EXE program size?
« Reply #47 on: April 11, 2021, 08:22:34 pm »
No, I was not thinking about Windows but embedded solutions that have few memory, mainly using Linux.

The point is that embedded solutions don't use full target RTLs, so comparing with that is useless.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: How to reduce EXE program size?
« Reply #48 on: April 11, 2021, 08:24:16 pm »
Unless you are still nursing one of those notorious Windows NT4 based printers :-)  (and FPC doesn't support <XP anymore)

Though that's not a problem of the compiler, but more of the RTL. So when throwing out features to decrease the RTL size one might possible get back support for NT4 or 9x back as well :P

alpine

  • Hero Member
  • *****
  • Posts: 1038
Re: How to reduce EXE program size?
« Reply #49 on: April 11, 2021, 08:29:34 pm »
@marcov
Sorry, that is what I have  :(
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: How to reduce EXE program size?
« Reply #50 on: April 11, 2021, 08:36:54 pm »
@marcov
Sorry, that is what I have  :(

Well, then you just have to believe me  that for small binaries, Delphi versions that support unicode are roughly twice as big.

FPK

  • Moderator
  • Full Member
  • *****
  • Posts: 118
Re: How to reduce EXE program size?
« Reply #51 on: April 11, 2021, 08:38:18 pm »
Hi!

I recognized that some people don't have a feeling what a kilobyte is related to a gigabyte. For those a graphic is always helpfull.

In the attachment.

Winni

Here with arduino 32 Kb ram + 2 KB flash.

% fpc11avr -Wpattiny10 empty.pp
Free Pascal Compiler version 3.3.1 [2021/04/11] for avr
Copyright (c) 1993-2021 by Florian Klaempfl and others
(1002) Target OS: Embedded
(3104) Compiling empty.pp
(9009) Assembling program
(9015) Linking empty
(1008) 2 lines compiled, 0.0 sec, 94 bytes code, 0 bytes data

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: How to reduce EXE program size?
« Reply #52 on: April 11, 2021, 08:48:22 pm »
@marcov
Sorry, that is what I have  :(

Well, then you just have to believe me  that for small binaries, Delphi versions that support unicode are roughly twice as big.

Empty console program compiled with Delphi 10.2 for Win32:

41 984 Byte

With WEAKLINKRTTI ON:

36 352 Byte

So marcov's estimation of roughly twice as big is correct. ;)

FPK

  • Moderator
  • Full Member
  • *****
  • Posts: 118
Re: How to reduce EXE program size?
« Reply #53 on: April 11, 2021, 08:50:23 pm »
And "Hello world" on Amiga 244 Bytes: https://github.com/chainq/amiga-tiny-hello-p

alpine

  • Hero Member
  • *****
  • Posts: 1038
Re: How to reduce EXE program size?
« Reply #54 on: April 11, 2021, 09:07:15 pm »
@marcov
Sorry, that is what I have  :(

Well, then you just have to believe me  that for small binaries, Delphi versions that support unicode are roughly twice as big.

I truly believe. I have not disputed it. Just tried to supply some figures.  ::)
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: How to reduce EXE program size?
« Reply #55 on: April 11, 2021, 11:43:54 pm »
My simple "Hello World" program is 49,815 bytes. Hmm..., can we strip it of unused libraries / data?

The attached picture shows the code section of that size, in which I think the rest of EXE are unrelated to displaying "Hello World" text string on console screen?

I thought I want to attempt writing a compress tool for FPC but (1) the output EXE is far more complicated that I thought, (2) it is best if it is done by the developer of the FPC itself (i.e. not outsider like me).  :D

Thank you for your attention.

A couple months back, I performed some informal testing across the systems on my network with varying executable sizes from a couple of applications, and came away with the following conclusions:

-- There is no substantial difference between the performance of one executable and another unoptimized version of the same, until there is at least a 250K size difference.
-- The newer the machine, the larger the difference in size needs to be, in order to make it noticeable -- even with logging
-- 10 year old systems running Windows are only a few dozen milliseconds slower in starting up than newer systems
-- The greatest contributing factor in startup performance is what AV or other end-point protection you are running  (I could literally shave 15-20 ms off the startup time based on which AV app was used)

It is such a non-factor that you will likely never reclaim the time you spent trying to optimize the performance via size.


-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: How to reduce EXE program size?
« Reply #56 on: April 11, 2021, 11:50:18 pm »
Hi!

I recognized that some people don't have a feeling what a kilobyte is related to a gigabyte. For those a graphic is always helpfull.

In the attachment.

Winni

Here with arduino 32 Kb ram + 2 KB flash.

% fpc11avr -Wpattiny10 empty.pp
Free Pascal Compiler version 3.3.1 [2021/04/11] for avr
Copyright (c) 1993-2021 by Florian Klaempfl and others
(1002) Target OS: Embedded
(3104) Compiling empty.pp
(9009) Assembling program
(9015) Linking empty
(1008) 2 lines compiled, 0.0 sec, 94 bytes code, 0 bytes data

Thats the way, héhé, héhé, I like it.

 ;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: How to reduce EXE program size?
« Reply #57 on: April 12, 2021, 05:14:27 am »
My simple "Hello World" program is 49,815 bytes. Hmm..., can we strip it of unused libraries / data?

One other point I intended to mention, but forgot.

Does it really matter what size "Hello World" compiles to, if "Hello World" is not your final product?    Meaning, you might go through all the work to strip down the RTL (or something else) to provide the barest of minimum sized executable, when that isn't your actual use case, and then you find out that all the things you stripped out are very much needed by the actual code you want to produce.

If you're even going to go through this exercise at all, shouldn't you at least do it with meaningful code that you actually need to run, and want to end up with?

Because it makes little sense to optimize anything else.  ;) ;)
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

Dodfr

  • Newbie
  • Posts: 6
Re: How to reduce EXE program size?
« Reply #58 on: June 30, 2021, 01:06:05 am »
Hi,
 
If your dev skills are pascal oriented and you still have a "good old" Delphi7 you may use KOL/MCK libs that permit to create very small apps including with visual components (limited to those from MCK libs that reproduce a lot of standard VCL component palette).

Simple helloworld inside a Form is 23KB, console version is smaller, adding visual components (MCK-KOL not VCL) do not increase size a lot.

A simple helloworld console mode is 8KB if I remember well.

Also to make EXE even smaller you can use ASM inline version of KOL libs instead of Delphi coded version.

Other trick with kol you can replace the standard sysutils with the one optimized with KOL.

So if you have some size coding contest and you are more comfortable with Pascal language than C/C++ then go for Delphi7+KOL/MCK, and whenever KOL/MCK development stopped I still use it time to time if I want small exe sized apps.

Appart from KOL/MCK if you want to reduce size of an EXE you can use strip.exe and EXE compressor like UPX (I think UPX do strip itself).

Regards.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: How to reduce EXE program size?
« Reply #59 on: June 30, 2021, 02:41:37 pm »
KOL is not Delphi only. It works with our favorite compiler as well...
https://wiki.freepascal.org/KOL
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

 

TinyPortal © 2005-2018