The worst thing about the delphi XE+ compiler is that it leaves dead i.e. unused code in generated binaries. It is very easy to prove, just create an empty console application and compile it. The size will be approximately 190kb. The project is empty and only System.SysUtils is used. Now add System.Classes to the uses list and compile the project. Its size will become near 600 kb. This is stupid, I didn't use any of System.Classes functions or objects, why are they present in the binary? Please don't say that this is made for extended RTTI support. This is bullshit. You just didn't spend enough time on optimizing the linker.

The worst thing about the delphi XE+ compiler is that it leaves dead i.e. unused code in generated binaries. It is very easy to prove, just create an empty console application and compile it. The size will be approximately 190kb. The project is empty and only System.SysUtils is used. Now add System.Classes to the uses list and compile the project. Its size will become near 600 kb. This is stupid, I didn't use any of System.Classes functions or objects, why are they present in the binary? Please don't say that this is made for extended RTTI support. This is bullshit. You just didn't spend enough time on optimizing the linker.
Please fix this, I think it's not so hard to do. We just want to deploy our application in many small dll's. Now it makes no sense as every dll adds 500kb and more waste space to the distributive.

Comments

  1. I've tried. It reduced the size from 530 to 490 kb.

    ReplyDelete
  2. Then I tend to agree that the linker elimination could use some tweaking.

    ReplyDelete
  3. That said - This is a corner case, and the reason Classes adds so much baggage can be found in it's initalization section.  You might argue that if nothing is referenced from Classes, that Init section should have been eliminated too - although it starts to get complex for a single pass compiler.

    ReplyDelete
  4. You are right. The problem is with initialization section. I copied Classes to my local folder, deleted the initalization and finalization sections, and replaced the System.Classes with my Classes. It reduced the binary size to 250 kb.Anyway, after removing this sections the file size should be the same as without linking Classes (180 kb), while it's not. I'm not complaining, I,m just trying to find solution for my problem, and for one day of work I reduced the size of some of my dlls up to 5-7 times. The fact is the problem has arised after our migration from Delphi 2006 to Delphi XE2, so I think this is compiler regression.

    ReplyDelete
  5. RTTI is indeed part of the problem, but some of that initialization code seems to be unnecessary, and I suspect similar code exists in other units as well.  Perhaps a result of less experienced developers failing to isolate functionality and ensure modularity?  

    As for the remaining size difference. Classes use a lot of other units, which again may have init sections.

    ReplyDelete
  6. I'd say most of the increase is not caused by the compiler. There were several changes made to the RTL and VCL between 2006 and XE2 that contributed significantly to binary size. Do a comparison of TObject in System.pas. It has at least double the number of methods. I'm no expert on the internals of the a object but it looks like the vmt was expanded quite a bit as well. Making UnicodeString the default string type doubled the size of every string variable you create.

    ReplyDelete
  7. The compiler is partly to blame (it doesn't do whole program optimizations, like de-virtualization and eliminating unused virtual methods and all that is "used" through those unused methods).

    But the main culprits are increased reliance on RTTI (everything in a class that has RTTI can't be smart-linked if that class is referred) and carelessness/spaghetti in the RTL/VCL.

    ReplyDelete

Post a Comment