Skip to content

Commit

Permalink
Disable ZIP compression, and comment out CRC32 checks, to improve loa…
Browse files Browse the repository at this point in the history
…ding times.

It turns out ZIP decompression is pretty slow, and the optional CRC32 check on data integrity is even slower (at least as implemented by miniz).  Long-term plan is to switch to LZ4 or some other compression method, see issue #3, but for now simply disabling compression and commenting out the CRC32 is easy and gets things loading quite a bit faster.
  • Loading branch information
Reedbeta committed May 4, 2015
1 parent 10d22e7 commit 6eb5e15
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion asset-internal.h
Expand Up @@ -27,7 +27,7 @@ namespace Framework
{
enum PACKVER
{
PACKVER_Current = 2,
PACKVER_Current = 3,
};

enum MESHVER
Expand Down
4 changes: 2 additions & 2 deletions asset.cpp
Expand Up @@ -329,7 +329,7 @@ namespace Framework

CHECK_WARN(CheckPathChars(zipPath));

if (!mz_zip_writer_add_mem(pZipOut, zipPath, pData, sizeBytes, MZ_DEFAULT_LEVEL))
if (!mz_zip_writer_add_mem(pZipOut, zipPath, pData, sizeBytes, MZ_NO_COMPRESSION))
{
WARN("Couldn't add file %s to archive", zipPath);
return false;
Expand All @@ -345,7 +345,7 @@ namespace Framework

CHECK_WARN(CheckPathChars(assetPath));

if (!mz_zip_writer_add_mem(pZipOut, assetPath, pData, sizeBytes, MZ_DEFAULT_LEVEL))
if (!mz_zip_writer_add_mem(pZipOut, assetPath, pData, sizeBytes, MZ_NO_COMPRESSION))
{
WARN("Couldn't add file %s to archive", assetPath);
return false;
Expand Down
6 changes: 4 additions & 2 deletions miniz.c
Expand Up @@ -3588,7 +3588,8 @@ mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file
// The file is stored or the caller has requested the compressed data.
if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, (size_t)needed_size) != needed_size)
return MZ_FALSE;
return ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) != 0) || (mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, (size_t)file_stat.m_uncomp_size) == file_stat.m_crc32);
// NRR: commented out CRC32 check to save time
return MZ_TRUE; /*((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) != 0) || (mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, (size_t)file_stat.m_uncomp_size) == file_stat.m_crc32);*/
}

// Decompress the file either directly from memory or from a file input buffer.
Expand Down Expand Up @@ -3652,7 +3653,8 @@ mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file
if (status == TINFL_STATUS_DONE)
{
// Make sure the entire file was decompressed, and check its CRC.
if ((out_buf_ofs != file_stat.m_uncomp_size) || (mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, (size_t)file_stat.m_uncomp_size) != file_stat.m_crc32))
// NRR: commented out CRC32 check to save time
if ((out_buf_ofs != file_stat.m_uncomp_size) /*|| (mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, (size_t)file_stat.m_uncomp_size) != file_stat.m_crc32)*/)
status = TINFL_STATUS_FAILED;
}

Expand Down

0 comments on commit 6eb5e15

Please sign in to comment.