Lazarus

Programming => General => Topic started by: lawman on January 20, 2020, 07:58:10 pm

Title: Compiled file size query
Post by: lawman on January 20, 2020, 07:58:10 pm
Hi,

New to lazarus.

Why does a GTK2 simple hello world gui with one button and one label take 2.9mb size?

Same thing with Codeblocks wxwidgets gui takes 100k.

I've removed all debug info from binary but still 30 times bigger than C++ equivalent for hello world gui.

Can you advise?

Thanks
Title: Re: Compiled file size query
Post by: lucamar on January 20, 2020, 09:49:47 pm
There are several things that contribute to the size of Lazarus applications, among them the number of units which have to be included and a not small quantity of embedded resources: resourcestrings, form resource, standard icons, messages, etc.

The smallest I've ever been able to make a normal "do nothing" executable is around 2 MiB in 32 bits and around 3 MiB in 64 bits.

But note that if you write the program in pure old-style FPC (i.e. without resorting to the LCL or Lazarus niceties and managing everything in code) it's possible to reduce noticiably the size of the resulting executable. Of course, it's not exactly a Rapid (Development), easy route to take ;)
Title: Re: Compiled file size query
Post by: PaulRowntree on January 20, 2020, 09:52:59 pm
Edit : My mistake, I was addressing the wrong thread ... erased


Title: Re: Compiled file size query
Post by: lucamar on January 20, 2020, 10:00:04 pm
As noted in the FAQ sheet, you will find that the size of the executable is large (!) while you have the debugging information included; turning this Program Option off (presumably once the code shows no errors) reduces exe size significantly.

Yes, but the OP is talking about a 2,9 MiB exec, which is about the minimum for small, Release Mode, Lazarus programs. With debug info that will easily grow to a minimum of 30 to 50 MiB ...or more*! :o


* I've seen 500MiB (and bigger) executables, for medimu-size applications.
Title: Re: Compiled file size query
Post by: PaulRowntree on January 20, 2020, 11:42:31 pm
Oops, my mistake ... wrong thread.
Title: Re: Compiled file size query
Post by: Cyrax on January 21, 2020, 07:48:03 am
Hi,

New to lazarus.

Why does a GTK2 simple hello world gui with one button and one label take 2.9mb size?

Same thing with Codeblocks wxwidgets gui takes 100k.

I've removed all debug info from binary but still 30 times bigger than C++ equivalent for hello world gui.

Can you advise?

Thanks

The Widgeset glue (in this case GTK2) takes the major space. You can make your own pure GTK2 program, if you want but you will lose RAD functionality.
Title: Re: Compiled file size query
Post by: Hartmut on January 21, 2020, 10:58:16 am
Maybe these links can help you:
 - Why are the generated binaries so big and some Options to reduce size = https://wiki.lazarus.freepascal.org/Lazarus_Faq#Why_are_the_generated_binaries_so_big.3F
 - FAQ if size matters = https://wiki.lazarus.freepascal.org/Size_Matters

And you can run the "strip" command line utility (which comes with Lazarus) after compiling your executable.
Title: Re: Compiled file size query
Post by: avra on January 22, 2020, 08:30:12 am
Why does a GTK2 simple hello world gui with one button and one label take 2.9mb size?
Same thing with Codeblocks wxwidgets gui takes 100k.
You didn't count size of dynamically linked lib. On Windows wxWidgets DLL takes about 1.2MB when compiled with VS + size of your executable. Linux should not be much different. Try static linking and you will see how much size of Codeblocks wxwidgets gui dramatically increases.
Title: Re: Compiled file size query
Post by: PascalDragon on January 22, 2020, 09:07:56 am
Why does a GTK2 simple hello world gui with one button and one label take 2.9mb size?
Same thing with Codeblocks wxwidgets gui takes 100k.
You didn't count size of dynamically linked lib. On Windows wxWidgets DLL takes about 1.2MB when compiled with VS + size of your executable. Linux should not be much different. Try static linking and you will see how much size of Codeblocks wxwidgets gui dramatically increases.

But GTK2 (which is used by the LCL here) is also not statically linked and quite fat. So this comparison does not count.
Title: Re: Compiled file size query
Post by: HeavyUser on January 22, 2020, 09:35:24 am
Why does a GTK2 simple hello world gui with one button and one label take 2.9mb size?
Same thing with Codeblocks wxwidgets gui takes 100k.
You didn't count size of dynamically linked lib. On Windows wxWidgets DLL takes about 1.2MB when compiled with VS + size of your executable. Linux should not be much different. Try static linking and you will see how much size of Codeblocks wxwidgets gui dramatically increases.

But GTK2 (which is used by the LCL here) is also not statically linked and quite fat. So this comparison does not count.
No it holds up, wxWindows is to C++ what lcl is to pascal. ee a cross widget glue, well as far as I understand at least, never spend more than 2 hours on wxWindows so I might have missed some concrete widget code somewhere in there.
Title: Re: Compiled file size query
Post by: marcov on January 22, 2020, 10:41:04 am
New to lazarus.

Why does a GTK2 simple hello world gui with one button and one label take 2.9mb size?

Same thing with Codeblocks wxwidgets gui takes 100k.

I've removed all debug info from binary but still 30 times bigger than C++ equivalent for hello world gui.

Can you advise?

A library that has an abstraction for multiple widget layers will always be larger, but most of that size is initial only. (IOW the minimal program is larger, but the growth subsides quickly to a more moderate tempo). If you would develop mono widgetset programs in pascal, that would also be different.

IOW this is comparing apples (multi widgetset abstractions) and oranges (mono widgetset use)


Mininimal Windows programs can be as small as 32k

Best advise: don't care. What does it really matter ? We usually don't carry binaries around on floppies anymore.
Title: Re: Compiled file size query
Post by: PascalDragon on January 23, 2020, 09:30:06 am
Why does a GTK2 simple hello world gui with one button and one label take 2.9mb size?
Same thing with Codeblocks wxwidgets gui takes 100k.
You didn't count size of dynamically linked lib. On Windows wxWidgets DLL takes about 1.2MB when compiled with VS + size of your executable. Linux should not be much different. Try static linking and you will see how much size of Codeblocks wxwidgets gui dramatically increases.

But GTK2 (which is used by the LCL here) is also not statically linked and quite fat. So this comparison does not count.
No it holds up, wxWindows is to C++ what lcl is to pascal. ee a cross widget glue, well as far as I understand at least, never spend more than 2 hours on wxWindows so I might have missed some concrete widget code somewhere in there.

No, it does not. The size of a hypothetical static wxWidgets application is the code of wxWidgets plus the application code. The code of a hypothetical LCL application is the size of the LCL, the widgetset libraries (e.g. GTK2 or Qt) and the application code. As the LCL is currently statically linked into the application already this whole static binary would likely be larger than the static wxWidgets binary.
Title: Re: Compiled file size query
Post by: Mr.Madguy on January 23, 2020, 09:34:16 am
Hi,

New to lazarus.

Why does a GTK2 simple hello world gui with one button and one label take 2.9mb size?

Same thing with Codeblocks wxwidgets gui takes 100k.

I've removed all debug info from binary but still 30 times bigger than C++ equivalent for hello world gui.

Can you advise?

Thanks
If Lazarus will ever support runtime packages, it's exe files will also become small.

For example my Delphi application:

1) Without runtime packages:
32bit - 1495Kb
64bit - 2121Kb

2) With runtime packages
32bit - 333Kb
64bit - 358Kb
Title: Re: Compiled file size query
Post by: PascalDragon on January 23, 2020, 10:15:28 am
If Lazarus will ever support runtime packages, it's exe files will also become small.
Then one needs into account the size of the packages. Here is a look at the sizes (in Byte) for chmls if using dynamic packages I did two months ago (https://lists.freepascal.org/pipermail/fpc-devel/2019-November/042223.html):

Quote from: Win32
2633984 rtl.dll
414820 rtl.objpas.dll
247060 rtl.extra.dll
364625 rtl.generics.dll
389888 fcl.res.dll
788664 fcl.base.dll
962560 fcl.xml.dll
953676 chm.dll
68694 chmls.exe

Quote from: Win64
3707538 rtl.dll
601446 rtl.objpas.dll
345340 rtl.extra.dll
459357 rtl.generics.dll
568559 fcl.res.dll
1187518 fcl.base.dll
1602915 fcl.xml.dll
1419896 chm.dll
85131 chmls.exe

For comparison the sizes of chmls without packages:
Win32: 460288
Win64: 623104
Title: Re: Compiled file size query
Post by: Mr.Madguy on January 23, 2020, 10:38:58 am
Then one needs into account the size of the packages. Here is a look at the sizes (in Byte) for chmls if using dynamic packages I did two months ago (https://lists.freepascal.org/pipermail/fpc-devel/2019-November/042223.html):
Yeah, that's, what I want to say. When you count application size - you should always take runtimes into account. For example Win C++ programs are small in comparison to Pascal ones, but we always forget about VS xxxx runtime. Or .Net applications, that also require .Net Framework. Delphi and Lazarus aren't that widespread and they don't have any deals with M$, so their runtimes just aren't treated as "standard". I.e. for example Delphi runtime packages are actually distributed the same way, as VS runtime. I.e. they can also be installed to System32 directory and therefore be available system wide. And after that Delphi applications can also look like "stand alone", while they actually aren't, and therefore look like they're much smaller, than they actually are.

Of course such small size of my Delphi app comes at expense of having:
1) rtlxxx.bpl
32bit - 2.8Mb
64bit - 4.0Mb
2) vclxxx.bpl
32bit - 3.3Mb
64bit - 4.8Mb
3) dyndataxxx.bpl
32bit - 43Kb
64bit - 62Kb
4) dyntestxxx.bpl
32bit - 411Kb
64bit - 546Kb

What's advantage of using packages then? They're SHARED between applications and their modules. My application has 36(!!!) modules. Without runtime packages they have 2x size. More modules you have - bigger advantage is. Yeah, I know, that all modules can be liked into one single exe in Lazarus. But it doesn't work for Delphi due to 2 reasons: 1) 32bit IDE, that has application/module size limit 2) It's designed around closed source applications.

And IMHO: splitting application between modules - is good development practice, especially for big and complex projects. So it isn't about "favoring proprietary technologies" only.
Title: Re: Compiled file size query
Post by: tetrastes on January 23, 2020, 03:55:06 pm
As the LCL is currently statically linked into the application already this whole static binary would likely be larger than the static wxWidgets binary.
You will be suprized, but
Code: Bash  [Select][+][-]
  1. D:\wxWidgets-3.1.1\samples\minimal\gcc_mswu_32>dir
  2.  
  3. 2020-01-23  19:28         7 348 736 minimal.exe
  4. ...
  5.  
(yes, stripped), and this is much bigger than any of my Lazarus app (with much bigger functionality  8-)).
I suspect that Linux things are something like that.
Title: Re: Compiled file size query
Post by: marcov on January 23, 2020, 04:34:56 pm
What's advantage of using packages then?

Primarily? NOT SIZE!

Packages are mainly to be able to compile parts of a program (e.g. a customer specific module) after the main program, without recompiling the original.
Title: Re: Compiled file size query
Post by: Thaddy on January 23, 2020, 04:40:13 pm
It is also an unfair comparison if you do not add the size of the package to the executable as well as any shared OS libraries.
FPC is well capable to produce binaries (without much dependencies) for embedded targets that are within a few hundred bytes....
Title: Re: Compiled file size query
Post by: luca on January 23, 2020, 04:53:15 pm
To reduce the size of the compiled project I'm using UPX tool.

In my case the size passes from 11MB to 3MB

Regards
Luca
Title: Re: Compiled file size query
Post by: Thaddy on January 23, 2020, 04:54:52 pm
That is not a real solution. It only saves storage space, not memory. It can also have side effects like out of memory.
Title: Re: Compiled file size query
Post by: Mr.Madguy on January 24, 2020, 07:54:42 am
Primarily? NOT SIZE!

Packages are mainly to be able to compile parts of a program (e.g. a customer specific module) after the main program, without recompiling the original.
That's, what I'm talking about. It's not problem for open source applications, as they can always be recompiled. In case of closed source programs - plugins are the only solution.
To reduce the size of the compiled project I'm using UPX tool.

In my case the size passes from 11MB to 3MB

Regards
Luca
As UPX modifies application memory, it prevents pages from: 1) Being discarded instead of unloaded to swap 2) Being shared between application instances. It's ok to use it for small stand alone applications, but it's not ok to use it for big complex projects, as it can cause waste of memory.
Title: Re: Compiled file size query
Post by: PascalDragon on January 24, 2020, 09:12:30 am
As the LCL is currently statically linked into the application already this whole static binary would likely be larger than the static wxWidgets binary.
You will be suprized, but
Code: Bash  [Select][+][-]
  1. D:\wxWidgets-3.1.1\samples\minimal\gcc_mswu_32>dir
  2.  
  3. 2020-01-23  19:28         7 348 736 minimal.exe
  4. ...
  5.  
(yes, stripped), and this is much bigger than any of my Lazarus app (with much bigger functionality  8-)).
I suspect that Linux things are something like that.
*shrugs* The LCL can't be smartlinked as aggressively due to its architecture, but as marcov said the growth isn't as extreme if new functionality is used.
Title: Re: Compiled file size query
Post by: marcov on January 24, 2020, 09:49:32 am
To reduce the size of the compiled project I'm using UPX tool.

In my case the size passes from 11MB to 3MB

And what exactly does this change really solve?

UPX is just another component that needs to be validated, and has known to cause problems (it doesn't support the full PE format, but only the part that is supported by GCC) and its binaries are more often flagged by antivirus software.

All problems that are IMHO bigger than the size. 11MB is still small on even a modest 128GB  SSD.
Title: Re: Compiled file size query
Post by: Thaddy on January 24, 2020, 10:38:39 am
AFAIK upx has been removed some years ago, while it was still a standard option in FreePascal. (and on my request)
Title: Re: Compiled file size query
Post by: lawman on January 24, 2020, 12:58:31 pm
when compiling, does lazarus only put the components used into the binary, or all of them?
Title: Re: Compiled file size query
Post by: marcov on January 24, 2020, 01:27:43 pm
when compiling, does lazarus only put the components used into the binary, or all of them?

Roughly the same as Delphi, for details how smartlinking works, see this post: https://stackoverflow.com/questions/4519726/delphi-which-are-the-downsides-of-having-unused-units-listed-in-the-uses-clause/4519894#4519894
Title: Re: Compiled file size query
Post by: Handoko on January 24, 2020, 01:56:44 pm
Why does a GTK2 simple hello world gui with one button and one label take 2.9mb size?

Same thing with Codeblocks wxwidgets gui takes 100k.
Thanks

A simple hello world program cannot show the power of the programming tool.

Long time ago, I wrote a simple stock control program for my friend who running a small shop. It was my first and 'real' program written using Lazarus. The program has basic stock control features: stock in/out/reject, basic reporting and printing features without any accounting calculations. The program only consists of 1 single binary, no dll and the file size is only 4,3 MB. On its first run it will automatically generate some dbf files. No installation headache, simple copy to your computer and run it. Backup is extremely easy, copy/paste the folder to your flashdrive.

After that, then I was sure that Lazarus is worth for my time.

Before I use Lazarus, I had a non-licensed copy of Delphi 7. I checked the price, it was something around $3000. I can't afford it for my hobby projects and I respected their license term. Luckily there was Lazarus. The early versions of Lazarus were buggy, but not now. Thank you Lazarus' team for making it so awesome.
TinyPortal © 2005-2018