Wil van Antwerpen 25 Posted June 22, 2021 Back in Delphi 5, Delphi 7 etc... I did built a few DLL's and I was amazed by how small they ended up. Creating a nice control under 100kB was normal. Nowadays, with Delphi 10.4 building any control under 2MB looks like it is a challenge. Has anything changed here? Is this because I am using VCL and is VCL pulling in 2MB for that? (If so I have to see if I can't eliminate the usage of VCL) I don't see this happening if I built a component in C++ with Visual Studio. Has anyone any tips on how-to reduce the size of the resulting binary DLL or ActiveX? Looks to me that I am just missing something basic here. Btw, just saying, I'm not interested in packers. I prefer to just cut the "bloat", not compress it. Thanks for any ideas. Share this post Link to post
Pat Foley 51 Posted June 22, 2021 Quote Turn off RTTI if you can. That can save 400K For big savings remove Classes 1.5 M and SysUtils .2 M from the uses clause for a smaller lib. 1 Share this post Link to post
dummzeuch 1505 Posted June 22, 2021 1 hour ago, Pat Foley said: That can save 400K For big savings remove Classes 1.5 M and SysUtils .2 M from the uses clause for a smaller lib. I can't really imagine writing any code > WriteLn('hello world'); without using SysUtils and Classes. And I doubt that many will go this way. Eliminating the VCL is a different matter. That's possible if the lib doesn't need a UI. But I would probably not even try that nowadays, not to just save a few megabytes. 1 Share this post Link to post
Wil van Antwerpen 25 Posted June 22, 2021 Thanks. I was afraid that it would be hard. I tried to get rid of some standard packages.. but didn't see a byte difference. None of the suggested packages are easy to remove as that would trigger a lot of extra -hard to maintain- work. Looks like I will have to learn to live with it for now. Somehow I had expected that the compiler was smarter and not include parts of the packages I'm not using, but I can see how that's a bit of a pipe dream. At least I now know what parts to pay attention to. -- Wil Share this post Link to post
David Heffernan 2345 Posted June 22, 2021 If you really need to do this then you probably need to switch to a different tool, or use an old version of Delphi. Modern Delphi just produces huge executables. Or you could just decide not to worry about a few MBs. 1 Share this post Link to post
Wil van Antwerpen 25 Posted June 22, 2021 Thanks David, yes that seems to be the case. While other tools can be useful, quite often it is faster to build something in Delphi. Going back to using a very old version is most of the times not the best solution. Much appreciate all the replies. Share this post Link to post
Lars Fosdal 1792 Posted June 23, 2021 16 hours ago, dummzeuch said: I can't really imagine writing any code > WriteLn('hello world'); without using SysUtils and Classes. I agree. They are the bread and butter of most apps. Still, it makes you wonder why the linker cannot eliminate more of the unused stuff. Share this post Link to post
Dalija Prasnikar 1396 Posted June 23, 2021 7 minutes ago, Lars Fosdal said: I agree. They are the bread and butter of most apps. Still, it makes you wonder why the linker cannot eliminate more of the unused stuff. Because enhanced RTTI is now turned on for RTL/VCL with rather poor default (and of course, FMX, but FMX was never without it) and that RTTI prevents removing unused things with linker. So any class you touch or is touched by other code, will be almost completely included in executable. Unused classes are not included. Default visibility for methods is public and published, for fields private, protected, public, published and for properties public, published. There is also WEAKLINKRTTI directive, that enables linker to eliminate unused symbols with RTTI, but it is not turned on in core Delphi frameworks. http://docwiki.embarcadero.com/RADStudio/Sydney/en/WEAKLINKRTTI_directive_(Delphi) 2 Share this post Link to post
Lars Fosdal 1792 Posted June 23, 2021 Ok, that explains it until the next time I've forgotten about it. Thanks, @Dalija Prasnikar 🙂 Share this post Link to post
Fr0sT.Brutal 900 Posted June 28, 2021 I have x64 DLL that uses SysUtils and DateUtils weighting 590 Kb compiled with XE2. Unfortunately, RTL is not designed having little binary size in mind (bloated Classes unit that you have to include just when you need TStream). Share this post Link to post
Kazantsev Alexey 24 Posted June 28, 2021 1 hour ago, Fr0sT.Brutal said: I have x64 DLL that uses SysUtils and DateUtils weighting 590 Kb compiled with XE2. library rtltest; //{$weaklinkrtti on} uses system.classes; begin TMemoryStream.Create.Free; end. Delphi XE2, x86_64, Release: default - 547840 bytes + weaklinkrtti on - 505344 bytes + custom rtl build with minimal rtti - 256000 bytes 1 Share this post Link to post
Lars Fosdal 1792 Posted June 28, 2021 On the other hand - I use RTTI quite a bit. Share this post Link to post
Fr0sT.Brutal 900 Posted June 28, 2021 31 minutes ago, Kazantsev Alexey said: Delphi XE2, x86_64, Release: default - 547840 bytes + weaklinkrtti on - 505344 bytes + custom rtl build with minimal rtti - 256000 bytes Nice note. How did you produce custom RTL build? Just putting Classes and all its used units near the project or recompiled all units somehow? Share this post Link to post
Kazantsev Alexey 24 Posted June 28, 2021 (edited) 1 hour ago, Fr0sT.Brutal said: How did you produce custom RTL build? For XE2 you need explicitly rebuild the three files (for latest versons need some more rtl files be rebuilded): system.pas (with key -Y) system.sysutils.pas (with key -V-) system.variants.pas (with key -V-) (search path should include rtl sources) When project building seach path should include your own custom rtl dcus, and rtl sources after it. Edited June 28, 2021 by Kazantsev Alexey 1 Share this post Link to post
Kazantsev Alexey 24 Posted June 28, 2021 4 hours ago, Kazantsev Alexey said: library rtltest; //{$weaklinkrtti on} uses system.classes; begin TMemoryStream.Create.Free; end. Delphi XE2, x86_64, Release: default - 547840 bytes + weaklinkrtti on - 505344 bytes + custom rtl build with minimal rtti - 256000 bytes The same example on 10.4.2: 1770kb, 1279kb, 456kb Share this post Link to post
PeterPanettone 157 Posted June 29, 2021 On 6/22/2021 at 4:23 PM, Wil van Antwerpen said: Somehow I had expected that the compiler was smarter and not include parts of the packages I'm not using That would the BIGGEST INNOVATION in Delphi ever, giving Embarcadero a 500% boost to Delphi sales. Share this post Link to post
Wil van Antwerpen 25 Posted June 29, 2021 14 minutes ago, PeterPanettone said: That would the BIGGEST INNOVATION in Delphi ever, giving Embarcadero a 500% boost to Delphi sales. LOL, it should, but sadly nobody really cares about the size of a binary these days. Having to roll (and maintain) your own version of a standard unit sadly isn't time best spent either. Share this post Link to post