0
\$\begingroup\$

Compression and encryption are different things AFAIK, so why even use compression if you have to still decompress anyway, is this just to reduce distribution size or is there some other reason?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Compress what and where? \$\endgroup\$
    – Philipp
    Commented Sep 17, 2014 at 14:49
  • \$\begingroup\$ Compression: In my game I currently have 1000 levels. And only 1 of those is played at a time, so it's daft to store each 1000 levels in raw format. Instead I compress each level individually using zlib and just decompress the current level as needed. Saves huge amounts of space on the device and in download time from the app stores. Encryption: I use this on my backend server to encrypt a JSON Web Token to authenticate my user. I like to send the client an encrypted token which is like a day pass to access backend services. I don't particularly want the client to read its contents. \$\endgroup\$
    – user24493
    Commented Aug 12, 2021 at 8:13

4 Answers 4

6
\$\begingroup\$

Mainly compression is used to reduce the size of the distributive and game resource package. You should distinguish compression of the distributive and the resource package of the installed game. The distributive usually is compressed by high compression ratio algorithms, while the package of installed game can be compressed by algorithms with fast decompression speed to be able to decompress it on fly. For the distribution there is only one benefit - reduction of its size. However, for the package of installed game the benefit is not only a reduction of its size, but also possible a light speed up of file read operations. The resource package of the installed game might not be compressed, it is not always necessary.

The speed up of read operations could be achieved in case of slow disk read operations (mobile devices for example) and using algorithms with very fast decompression speed, such as LZ4

On mobile devises, I have noticed the following thing. The ratio of read time of compressed data to decompression time with LZ4 can be up to ten times. So depending on compression ratio, you can chose what types of files should be compressed and what not.

You should be aware of the following disadvantages of on fly decompression:

  • It is hard to implement streaming of compressed data and there could be serious loss of performance.
  • Memory consumption would be increased due to the need of allocating buffers for decompression.
\$\endgroup\$
1
  • \$\begingroup\$ Rreading from a rotating disk is super slow. Even the xbox one gets a budget of 10MB/s (recommended by microsoft). This is low. If you have a need to stream data at more than that you need to compress. \$\endgroup\$
    – v.oddou
    Commented Sep 18, 2014 at 1:52
3
\$\begingroup\$

Mainly compression is in fact used to reduce distribution size.

If you think about it with digital music, you could download a CD as .wav and it's 650 MB, or as 256 KBPS AAC files and it's 1/5 the size with the same sound quality*.

It just makes sense to compress anything you can. You're taking the compression time on your side once to save time downloading or reduce storage media size for everyone who uses the product.

As a side note, yes encryption is different from compression. Encryption makes it hard to read the data if you're not the intended recipient. When making an iOS game, we send a compressed archive to Apple, then they encrypt it, which makes the package bigger.

* I have done blinded testing on this. There's no discernable difference between uncompressed audio and 256 KBPS AAC audio.

\$\endgroup\$
6
  • \$\begingroup\$ when you tested AAC did you test with (almost) profesional grade headset and sound card ? may be quite off topic though. \$\endgroup\$
    – v.oddou
    Commented Sep 17, 2014 at 5:00
  • \$\begingroup\$ Since this is an argument I don't want to have again, I'll just say this. I've done blinded tests with both an expensive stereo, and expensive headphones. The baseline test showed the subject could hear the difference if they knew which was which. As soon as the blinders go on, there is zero ability to discern the difference. So if you haven't done a blinded test, it's all in your head. :) \$\endgroup\$
    – Almo
    Commented Sep 17, 2014 at 12:31
  • \$\begingroup\$ That's debatable, have you ever seen blind food taste tests, it's amazing how people can't identify chicken, beef or most foods for that matter, after their palette has been trained it's a different story. \$\endgroup\$ Commented Sep 17, 2014 at 13:03
  • \$\begingroup\$ One of the subjects was a musician. There are other factors with food; like texture and scent. Until you've done a blind test with this stuff, anything else is speculation on your part. Here's an example of just such a test, but this one is about amplifiers: tom-morrow-land.com/tests/ampchall \$\endgroup\$
    – Almo
    Commented Sep 17, 2014 at 13:43
  • \$\begingroup\$ To prevent getting lost in semantics, how about you say "with no quality differences I could discern"? Or better, aking a comparison to FLAC, or other lossless algorith which is closer to the idea of compression in game assets \$\endgroup\$ Commented Sep 18, 2014 at 1:44
3
\$\begingroup\$

A big reason to compress game assets is to decrease loading times.

Example scenarios:

  1. Read uncompressed asset of 20MB size, or
  2. Read compressed asset of 10MB size and decompress.

In scenario 2 less data needs to be read from the hard disk which will save some time. If the CPU is faster at decompressing the read 10MB to the original 20MB than the hard disk in scenario 1 is capable of reading the remaining 10MB, compression will improve the loading time. Note that hard disks are generally much slower than CPUs. Many algorithms (you mentioned zlib's) even allow decompression on the CPU while the hard disk is reading in parallel.

You should pick an algorithm that

  1. compresses well (to reduce the time spent reading from the hard disk) and
  2. decompresses quickly (to reduce the time decompressing using the CPU).

Algorithms that would increase loading times are used when compressed size on disk is more important than decompression time, for example during installation of the game assets.

\$\endgroup\$
1
  • \$\begingroup\$ exactly. that's the main reason for a complicated geometry compression algorithm developped for alembic cache files in crytek's Ryse. \$\endgroup\$
    – v.oddou
    Commented Sep 17, 2014 at 5:01
0
\$\begingroup\$

The answer is time

Use Compression?
    if uncompressed (down)load time > compressed (down)load time+decompress time then
        Win! use compression
    else   
        Lose! don't bother
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .