Recent

Author Topic: Compiled file size query  (Read 2901 times)

lawman

  • New Member
  • *
  • Posts: 41
Compiled file size query
« 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
« Last Edit: January 20, 2020, 08:28:32 pm by lawman »

lucamar

  • Hero Member
  • *****
  • Posts: 3019
Re: Compiled file size query
« Reply #1 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 ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

PaulRowntree

  • Full Member
  • ***
  • Posts: 132
    • Paul Rowntree
Re: Compiled file size query
« Reply #2 on: January 20, 2020, 09:52:59 pm »
Edit : My mistake, I was addressing the wrong thread ... erased


« Last Edit: January 20, 2020, 11:43:27 pm by PaulRowntree »
Paul Rowntree
- coding for instrument control, data acquisition & analysis, CNC systems

lucamar

  • Hero Member
  • *****
  • Posts: 3019
Re: Compiled file size query
« Reply #3 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.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

PaulRowntree

  • Full Member
  • ***
  • Posts: 132
    • Paul Rowntree
Re: Compiled file size query
« Reply #4 on: January 20, 2020, 11:42:31 pm »
Oops, my mistake ... wrong thread.
Paul Rowntree
- coding for instrument control, data acquisition & analysis, CNC systems

Cyrax

  • Hero Member
  • *****
  • Posts: 832
Re: Compiled file size query
« Reply #5 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.

Hartmut

  • Sr. Member
  • ****
  • Posts: 423
Re: Compiled file size query
« Reply #6 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.

avra

  • Hero Member
  • *****
  • Posts: 2000
    • Additional info
Re: Compiled file size query
« Reply #7 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.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

PascalDragon

  • Hero Member
  • *****
  • Posts: 2104
  • Compiler Developer
Re: Compiled file size query
« Reply #8 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.

HeavyUser

  • Sr. Member
  • ****
  • Posts: 310
Re: Compiled file size query
« Reply #9 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.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8720
  • FPC developer.
Re: Compiled file size query
« Reply #10 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.
« Last Edit: January 22, 2020, 10:48:51 am by marcov »

PascalDragon

  • Hero Member
  • *****
  • Posts: 2104
  • Compiler Developer
Re: Compiled file size query
« Reply #11 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.

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 564
Re: Compiled file size query
« Reply #12 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
DynamicData 3.0 is released!
Since now development is frozen - only optimization passes will be made at some point.
Lack of multiple inheritance turns it into abomination.

PascalDragon

  • Hero Member
  • *****
  • Posts: 2104
  • Compiler Developer
Re: Compiled file size query
« Reply #13 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:

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

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 564
Re: Compiled file size query
« Reply #14 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:
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.
« Last Edit: January 23, 2020, 11:22:00 am by Mr.Madguy »
DynamicData 3.0 is released!
Since now development is frozen - only optimization passes will be made at some point.
Lack of multiple inheritance turns it into abomination.

 

TinyPortal © 2005-2018