Recent

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

y.ivanov

  • Jr. Member
  • **
  • Posts: 85
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

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9258
  • 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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9258
  • 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: 2955
  • 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

y.ivanov

  • Jr. Member
  • **
  • Posts: 85
Re: How to reduce EXE program size?
« Reply #49 on: April 11, 2021, 08:29:34 pm »
@marcov
Sorry, that is what I have  :(

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9258
  • 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
  • Jr. Member
  • *****
  • Posts: 94
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: 2955
  • 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
  • Jr. Member
  • *****
  • Posts: 94
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

y.ivanov

  • Jr. Member
  • **
  • Posts: 85
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.  ::)

ASBzone

  • Hero Member
  • *****
  • Posts: 615
  • 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.0.13 r64843 / FPC v3.2.1-r49055 (via FpcUpDeluxe) -- Windows 64-bit install w/Win32 and Linux/Arm cross-compiles
Primary System: Windows 10 Pro x64, Version 2009 (Build 19042)
Other Systems: Windows 10 Pro x64, Version 2009 (Build 19042) or greater

Fred vS

  • Hero Member
  • *****
  • Posts: 2210
    • 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.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

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

ASBzone

  • Hero Member
  • *****
  • Posts: 615
  • 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.0.13 r64843 / FPC v3.2.1-r49055 (via FpcUpDeluxe) -- Windows 64-bit install w/Win32 and Linux/Arm cross-compiles
Primary System: Windows 10 Pro x64, Version 2009 (Build 19042)
Other Systems: Windows 10 Pro x64, Version 2009 (Build 19042) or greater

 

TinyPortal © 2005-2018