5

At one point I had a nice little compression utility that smashed my Delphi compiled EXE's to a smaller download size, but now I can't find it. Any recommendations?

Also, are there any downsides to using these kinds of utilities? (I mainly use them to shorten download times for rural / dial-up users).


Related question: Are there any downsides to using UPX to compress a Windows executable?

Community
  • 1
  • 1
Jamo
  • 3,238
  • 6
  • 40
  • 66
  • That's very close to being a duplicate - I added a link to the other relevant question in [delphi]. – mghie Apr 29 '09 at 04:12

12 Answers12

13

Years ago I looked into compressing my executable to make the download smaller.

What I ended up doing, and what I recommend for you, is to use an installer program like Inno Setup instead. Not only does it create a single EXE that will install/uninstall your program, but it also compresses that EXE practically as much as a separate compressor would do to your executable alone.

When the program is installed it gets decompressed, so it never appears to be a virus and does not increase load times.

So I get the benefits of smaller download size, and a professional-looking installation script at the same time.

p.s. Inno Setup is free.

lkessler
  • 19,819
  • 36
  • 132
  • 203
  • 4
    +1 for the Inno Setup tip: It includes deflate, bzip2 and 7-Zip LZMA file compression, so very small installers are possible. It will shine if there are similar files to compress, I have an installation where the ZIP package is about one third larger than the installer file (both containing the same files). – mghie Apr 29 '09 at 04:20
12

The recommendation is that you not:

  • EXE compressors can make your application seem like a virus (self-modifying)
  • gzip/zip are just as effective at compressing and don't tinker with your app
  • EXE compressors make the load times of your app increase (unless you're just talking about the setup program which is a different matter

This crazy looking site brings up an argument I had heard in the distant past (whether it's true or not still today, I'm not sure, modern packers probably have a different strategy today) This article references Win32! :)

http://topic.csdn.net/t/20000408/08/6785.html

Modern multitasking OSes such as Windows 95/98 and NT use what is called a "virtual memory" system. When programs start, all of their code is not loaded into memory immediately upon startup, as was the case with DOS programs. Instead, only portions of the code being actively executed are stored into memory. For example, say your program has a Print option on its menu, and code behind it that handles the printing. This code will only be loaded into memory once the Print feature is first selected by the user. And if after the code is loaded into memory the Print feature is not used for a while the system will "discard" the code, freeing the memory it occupied, if another application desperately needs memory. This is part of a process called "paging" and is completely transparent to the program.

Another way paging under Win32 conserves memory is it causes multiple instances of a program (or DLL) to share the same memory for code. In other words, under normal circumstances there is no real difference in the amount of physical memory allocated for code between starting 100 instances of a program and starting one instance.

If all Win32 programs behaved like DOS programs, loading everything into memory and keeping it there until the program terminated and also not sharing any memory between multiple instances, you can probably imagine how quickly physical memory could run out on systems with a limited amount, causing disk swapping to start.

Yet this is precisely what current Win32 EXE compressors do to your EXE's/DLL's! They completely go against the OS's paging system by decompressing all code into memory and keeping it there until termination. And because code isn't stored in a "raw" format in the EXE file (i.e. the same way it is stored in memory), the OS is unable to share code between multiple instances.

cgp
  • 41,026
  • 12
  • 101
  • 131
  • 2
    See also: http://jrsoftware.org/striprlc.php#execomp – Tim Sullivan Apr 29 '09 at 01:33
  • 2
    A coworker did some benchmarking with and without UPX. UPX ended up being a win for network shares and a loss for local drives. Of course I can't quote actual numbers at you (I don't remember them, and they would be specific to our code), so feel free to ignore me :). – Logan Capaldo Apr 29 '09 at 01:53
  • Jordan Russell (jrsoftware) is the developer of Inno Setup, and the link that Tim Sullivan refers to in his comment above is to the StripReloc program by Jordan. So Jordan obviously is an expert on compression and it could be assumed that he did it right in Inno Setup. – lkessler Apr 29 '09 at 06:17
  • 1
    Please also see my comment below about how modern compressors like PECompact can avoid shared sections of DLLs and mitigate these concerns in other ways. I don't want to repeat myself, but just to say that in *some* cases they are useful, in others they aren't. That's the bottom line. I don't think there is a definitive 'BAD' or 'GOOD', just another utility – dyasta Mar 12 '11 at 15:02
4

I don't know of any that are specifically for Delphi, but UPX is very popular for this sort of thing. The only downside is that the executable has to be decompressed when it's launched, and that can eat some time. It seems to be very fast for sanely sized executables, though.

Promit
  • 3,497
  • 1
  • 20
  • 29
4

The one you are probably thinking of is ASPack - it is a EXE compressor written in Delphi, but will compress any EXE. It might do extra well on Delphi EXE's though. I would agree with the other answers that you should not use an EXE compressor just to save on download times. There may be specific situations where an EXE compress is a good idea, but generally it is not.

Instead use a good installation builder, especially if you can find one that uses 7zip compression. I know InstallAware uses 7zip internally for maximum compression. Depending on which versions of Delphi you own you may have an InstallAware license too.

If nothing else you can build a self extracting archive with basic install behavior with 7zip for free. It is a separate download for SFXs for installers.

Jim McKeeth
  • 38,225
  • 23
  • 120
  • 194
  • 2
    After having seen the Delphi 2007 installation in action I wouldn't touch InstallAware with the proverbial 10-foot pole. I can' believe that using it would not add more than the compression of the executable reduces in size. – mghie Apr 29 '09 at 04:16
  • 4
    I think Embarcadero should have used innosetup for the Delphi setup. I recently had to make a complex setup including SQL Server 2008, downloading requisite component during install. Couldn't believe how great Inno Setup was, as soon as I got into it. – Tom Apr 29 '09 at 06:55
  • 1
    InnoSetup really is awesome and couldn't recommend it more. I've done some very compless install with it. Would never go back to Wise/InstallShield etc... – Nazar Apr 29 '09 at 08:32
  • 1
    It's not WISE or InstallShield that you dislike, it's Microsoft Installer (MSI) technology. I disagree with you all. I prefer building MSI's...however I usually use Orca but that's because I'm very very familiar with MSI internals. I also write my own custom action DLL's, in Delphi no less. The problem is, too many people use WISE and InstallShield to create crap MSI's when they don't know what they are doing. – Mick Apr 29 '09 at 14:17
  • 2
    I have used all of the mentioned installers at one time or another and short of the inability to work with existing MSI packages, InnoSetup is by far the easiest to use, configure and extend. I strongly also suggest the ISPack editor and extensions which make editing scripts that much easier. – skamradt Apr 29 '09 at 15:45
  • @Mick, no, MSI is okay, it is installaware who unpacks passworded 7-Zip archives and pack it back with NTFS compression. Guess how quick it works and how easy to restore accidentally modified file. down with mimar sinan! – Free Consulting Nov 14 '10 at 22:13
3

Use UPX with lzma option for max compression.

upx --lzma yourfile.exe
samir105
  • 949
  • 11
  • 16
2

The main inconvenience of a compressed EXE or DLL is that the OS cannot share the code amongst multiple instances.
So you're wasting memory, have to decompress each time you start an instance, exhibit a virus-like behavior without even an download advantage over a compressed install.
Only positive case is when launching directly from a network drive.

user81126
  • 111
  • 1
  • 4
  • Yes, it can share code, but it depends on how it is packed. Most shared code is in DLLs. PECompact ignores shared sections of DLLs by default, for example. Also, if you don't compress your DLLs, then shared memory between process instances of those DLLs isn't affected by the compression of your main EXE. – dyasta Nov 29 '10 at 21:53
1

I believe Terminal servers (Like Citrix) will use the same memory for you're application binary if it is uncompressed. Meaning a compressed exe could smell a small disaster in a Citrix environment.

Tom
  • 1,381
  • 3
  • 15
  • 26
  • 1
    It is called 'shared memory' and is used in cases of multiple instances of an EXE or DLL. It is not just Terminal Servers that use it, but all modern OSes. The idea is simple. If the virtual memory page (4KB) already exists, then simply reference it. If an individual process changes that memory, then it privatizes it in a method known as copy-on-write. HOWEVER, you need to remember that not all executable compressors behave the same, and some can be configured/default to skip shared sections. – dyasta Nov 29 '10 at 21:16
0

UPX should work, although it's not Delphi specific.

Logan Capaldo
  • 39,555
  • 5
  • 63
  • 78
0

I use PEtite: http://un4seen.com/petite/

J__
  • 3,777
  • 1
  • 23
  • 31
0

I would also vote for upx. Beside the downsides which were mentioned it also protects from basic reverse engineering and those lame "resource hacker" tools. Which by the way are plenty, and most of them fail to open a compressed executable.

zz1433
  • 3,528
  • 2
  • 28
  • 36
0

I asked a question about the con's of using UPX on Delphi executables here on SO a while back, and I got some great responses.

Are there any downsides to using UPX to compress a Windows executable?

Community
  • 1
  • 1
Mick
  • 13,248
  • 9
  • 69
  • 119
-1

You can use PECompact since people can't decrypt it easily, and as test showed (showed on main page, just scroll down a bit) it's better than ASPack or UPX, i've using it on my previous Delphi projects

Dels
  • 2,375
  • 9
  • 39
  • 59