0

I have a little console app that I use in an installer to set registry settings and date stuff. Its only 80 lines of code, no units, all done in the main program file. It was originally compiled in D2007 and compiled exe size is 84kB.

I am trying to compile the file in XE8 32 bit and its compiled size is 1MB.

I expect a bit of an increase with new versions, but 12 times bigger is exceptionally bad by any standard.

It been compiled in release mode with all the debugging options turned off.

The uses clause includes only "registry,Windows,dateutils,SysUtils".

Is this normal or have I missed some other settings to turn off?

Andy k
  • 1,056
  • 1
  • 11
  • 22
  • Discussed many times, i believe there is nothing special with XE8, EXE is growing with every version of Delphi. So old answers are relevant, you can start here http://stackoverflow.com/questions/13598678/exe-size-is-too-big-in-delphi-xe2 Probably best solution is to write "registry settings and date stuff" from installer, most of installing engines can do that for you. – Andrei Galatyn Aug 04 '15 at 14:21
  • 1
    http://stackoverflow.com/questions/3199476/what-can-i-do-to-reduce-my-executables-size-delphi and http://stackoverflow.com/questions/16377711/delphi-xe3-exe-file-size-25-times-larger-than-dephi-7 – LU RD Aug 04 '15 at 14:24
  • You can disable RTTI: http://stackoverflow.com/questions/3975292/delphi-xe-disable-rtti You can also extract the code you need from these units into your own copy and exclude the rest, or, in general, use direct Windows API calls (specifically for registry). – Jerry Dodge Aug 04 '15 at 14:38
  • 2
    Please show an MCVE. – David Heffernan Aug 04 '15 at 14:38
  • Yes, I have seen the other questions and they provide no answers. Tried the RTTI trick and it makes absolutely no difference, which is to be expected as I am not using classes and yes I am making direct windows calls for most stuff and no I can't do installer stuff from within the installer as its also doing some copy protection stuff. – Andy k Aug 04 '15 at 14:57
  • If you're using pure API calls for registry, then you wouldn't have `Registry` in your uses clause. – Jerry Dodge Aug 04 '15 at 15:08
  • I think the program icons can take up large space. – LU RD Aug 04 '15 at 15:27
  • @LURD Indeed, I've seen how Delphi automagically compiles some image resources with applications. Not sure about Console ones though, might just be VCL. But I've seen those ugly old 16bit icons which nobody's used since 1999 embedded as resources. – Jerry Dodge Aug 04 '15 at 15:41
  • @Jerry, using API for most things but not the registry. Commenting out the registry bits out brings it down to 258K. That's a huge saving, there must be quite a lot of dependencies in that unit to load up 750k of junk. – Andy k Aug 04 '15 at 15:42
  • Just confirmed a console app doesn't compile these unnecessary icons as I mentioned. I'm curious why the `Registry` unit needs to use INI Files...? – Jerry Dodge Aug 04 '15 at 15:47
  • Please, please, show an MCVE. Please don't ask for specific help when you won't provide us with specifics. – David Heffernan Aug 04 '15 at 15:57
  • @JerryDodge: The `Registry` unit also implements the `TRegistryIniFile` class, which derives from `TCustomIniFile`, so it needs the `IniFiles` unit. When `TRegistry` was first introduced, `TRegistryIniFile` was provided as a migration path to let users move from INI files to the Registry without re-writing their existing INI code. `TRegistryIniFile` was never deprecated/removed, though it probably should be at this point. – Remy Lebeau Aug 04 '15 at 15:59
  • The other linked posts *do* provide the answer, which is that applications get larger as more and more things are added to them. In the case of D2009 and higher, the change from AnsiChar to Unicode alone resulted in significant increases in executable sizes. The solution is pretty simple: if you need your console app to stay the same size it was when compiled in D2007, compile it in D2007. – Ken White Aug 04 '15 at 18:08
  • A quick search here at SO on *delphi executable size* results in at least a half-dozen results covering this topic in some depth. I'm failing to see why this shouldn't be considered a duplicate of any one of them. – Ken White Aug 04 '15 at 18:21
  • @ken, yes looked at them, couldn't see anything about console apps. I don't have D2007 any more. Is it possible to use XE8 to call the ANSI versions of windows APIs and strip the unicode? – Andy k Aug 04 '15 at 19:07
  • 1
    In this day and age is 1Mb really worth the effort needed to go to or to look for a solution to reduce the size of the generated executables? – Craig Aug 04 '15 at 20:37
  • 1
    Andy, console apps make no difference. The EXE sizes have consistently increased over time, and there isn't really a lot you can do other than stick with the older version if size is that critical (or use KOL, as one of the answers in the prior questions mentions). And as @Craig mentions, when the ISO download for XE8 exceeds 7 **GB**, is a 1 **MB** size different in an installation utility really meaningful? – Ken White Aug 04 '15 at 21:28
  • If you really want to reduce the size, leave it in D2007 or code it in C++. – David Heffernan Aug 05 '15 at 06:42
  • @Craig Just like everything else size does not matter until it does. It is easy for devs sitting in their comfy chairs with their high end computers connected to reliable, cheap, high speed Internet connections seem to think that the rest of the world (including their customers) have the same. – Dalija Prasnikar Aug 05 '15 at 10:38
  • @DavidHeffernan Using older compilers is one solution, but that also includes maintaining your own code on different versions and that is not something desirable. When your base exe size grows because there are some new features added (like it is case with VCL) it can be tolerable. When it grows because new RTTI will include tons of dead code and because generics implementation is not optimized then people are rightfully annoyed. – Dalija Prasnikar Aug 05 '15 at 10:46
  • 1
    @DalijaPrasnikar The scenario presented is 80 lines of code. So the concerns are less significant. The asker can decide on how to proceed. One wonders why an install program is not used to be quite honest. – David Heffernan Aug 05 '15 at 10:54
  • @DalijaPrasnikar I see your point to a degree, but this is the year 2015 not 1995 :) Even the most basic PC systems these days carry enough storage capacity to handle such a dramatic change from a 84Kb File to a 1Mb File. And although network coverage and speed could be a factor for many people I repeat what I said before, a 1Mb File is just not worth getting worked up over. When you consider the File sizes of pretty much every other Application you realise that in the grand scheme of things 1Mb is actually tiny, If it was significantly more then fair enough, but come on 1Mb is tiny! – Craig Aug 05 '15 at 16:10
  • @craig It may come as some surprise to you that the world does not run on i7 laptops with 16GB of RAM. The vast majority of the world runs on embedded windows with 512MB of RAM and tiny flash drives. If you think that crippling compilers with bloatware is the way to get sales and then recommending that using some other language be used for these other jobs that need compact code, don't try applying for a job in sales at Embarcadero. – Andy k Aug 06 '15 at 07:53
  • @Andyk that is just not true, and who said anything about running on i7's and 16Gb memory? You can buy from new, cheap enough laptops and computers these days that come with ample amounts of storage capacity and decent enough processors. I just don't see the difference between a 84Kb File and a 1Mb File worth getting worked up over. A solution has been provided and that's all that matters, I would be more concerned if we were talking about much more significant sizes but this is really a non issue. It's also inevitable that with each IDE the File sizes grow, but why worry if the program works? – Craig Aug 06 '15 at 11:43

1 Answers1

2

Problem is in your uses list. You are using System.Win.Registry that uses System.Classes that uses System.RTTI.

(following sizes are for XE4, but XE8 should not be far off)

Empty console app with only System.SysUtils in uses is 122 KB in size. Add System.RTTI and you will end up with 962 KB.

Solution is to take out used RTL units, copy them to your project folder and add {$WEAKLINKRTTI ON} and {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])} to them.

For instance doing the above to System.RTTI and System.Classes will reduce console size to 417 KB.

Dalija Prasnikar
  • 27,212
  • 44
  • 82
  • 159