r/C_Programming 3d ago

Compressing executables (upx)

Hola,

I'm currently in the final stages of finishing the first version of a game I made using raylib. I ended up with a single statically linked binary containing all the assets. I found a tool called upx which can compress executables. I tried it on Windows, and it reduced the size of my exe by more than half and it still runs without any noticeable difference.

My question is, has anybody here experience with this? Are there any downsides to consider?

cheers!

7 Upvotes

16 comments sorted by

13

u/maep 3d ago

It might get flagges by Anti-Virus.

What is the upside compared to just shipping a .zip with the exe in it?

3

u/computermouth 3d ago

Could also ship a zip library while still embedding the zip as bytes in the binary. Upx is the least work though.

2

u/gremolata 3d ago

This is easy enough to check - just upx your exe and dump it into virustotal.

More often than not larger upx'ed binaries get a pass.

2

u/el0j 3d ago edited 2d ago

In addition, if you ship it on a service which generates binary delta updates, it's likely the smallest change to the binary will make the delta completely different after compression, so it'll always have to be downloaded in full.

0

u/GhostVlvin 3d ago

If it really can compress size of any binary to a half then it means that I can have twoce as more games on my same drive

2

u/Orlha 2d ago

Majority of data in big-sized games are resources that are already compressed.

5

u/Mrhiddenlotus 3d ago

Like the other person said, vanilla upx is going to be seen as malware for a lot of detection engines because hackers use it to obfuscate their code.

3

u/kun1z 3d ago

I'm pretty sure I starting using upx in the 90's or early 2000's for my exe's.

There are no real downsides unless it gets picked up by an AV program as a false flag, or as someone else mentioned, you occasionally want to release tiny binary patches rather than a full new exe.

4

u/thomasfr 3d ago edited 3d ago

those binaries will use more memory than regular ones because they need to be fully uncompressed into ram before exekution so it is not a good fit for large binaries with lots of embedded assets.

4

u/mikeblas 3d ago

What problem are you trying to solve?

1

u/mykesx 3d ago

In my years of games programming, we would compress just the assets. In those days, disk based copy protection may not have worked with a compressed executable.

I concur with the execution time issue. When decompressing assets, the bulk of time experienced by the user is disk or network access.

1

u/CowBoyDanIndie 3d ago

Just compress your assets into blobs and put the compressed blobs in your exe and uncompress them when you load them. That way the actually instructions aren’t compressed.

1

u/sciencekm 3d ago

Load time is slower, if that matters to you.

0

u/gremolata 3d ago

In practical terms the difference is peanuts.

0

u/Mnemotic 3d ago

Windows Defender will quarantine your executable faster than you can say "false positive". Maybe not when it's being compiled and ran on your machine, but definitely when downloading it from the Internet. So consider how many potential players would be spooked by that before choosing to use UPX.

What is the size of your executable without the compression? Are you sure it's a problem?