RCC: introduce compression algorithm "best"

This compression algorithm is permitted in the XML sources, which
instructs RCC to apply the best compression algorithm it has available.
If we have Zstandard available, that's its level 19 (levels 20 and up
are experimental). If not, we apply zlib compression level 9.

And apply this technique for the XDG MIME database that is built-in to
QtCore.
             Payload size  Compr. time
 Previously        313916    17.9ms
 Zlib -9           310899    53.6ms
 Zstd -14          253364    63.3ms (plus 4.0 ms on L1 heuristic check)
 Zstd -19          230647   642.5ms

Change-Id: I343f2beed55440a7ac0bfffd1562de44dbaf09cd
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Thiago Macieira 2018-10-31 19:13:29 -07:00
parent 2c9ac4fc3f
commit 57b4b45cbd
3 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/qt-project.org/qmime/packages">
<file alias="freedesktop.org.xml">mime/packages/freedesktop.org.xml</file>
<file alias="freedesktop.org.xml" compression-algorithm="best">mime/packages/freedesktop.org.xml</file>
</qresource>
</RCC>

View File

@ -258,6 +258,10 @@ qint64 RCCFileInfo::writeDataBlob(RCCResourceLibrary &lib, qint64 offset,
// Check if compression is useful for this file
if (data.size() != 0) {
#if QT_CONFIG(zstd)
if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Best) {
m_compressAlgo = RCCResourceLibrary::CompressionAlgorithm::Zstd;
m_compressLevel = 19; // not ZSTD_maxCLevel(), as 20+ are experimental
}
if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Zstd) {
if (lib.m_zstdCCtx == nullptr)
lib.m_zstdCCtx = ZSTD_createCCtx();
@ -301,6 +305,10 @@ qint64 RCCFileInfo::writeDataBlob(RCCResourceLibrary &lib, qint64 offset,
}
#endif
#ifndef QT_NO_COMPRESS
if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Best) {
m_compressAlgo = RCCResourceLibrary::CompressionAlgorithm::Zlib;
m_compressLevel = 9;
}
if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Zlib) {
QByteArray compressed =
qCompress(reinterpret_cast<uchar *>(data.data()), data.size(), m_compressLevel);
@ -824,6 +832,8 @@ RCCResourceLibrary::ResourceDataFileMap RCCResourceLibrary::resourceDataFileMap(
RCCResourceLibrary::CompressionAlgorithm RCCResourceLibrary::parseCompressionAlgorithm(QStringView value, QString *errorMsg)
{
if (value == QLatin1String("best"))
return CompressionAlgorithm::Best;
if (value == QLatin1String("zlib")) {
#ifdef QT_NO_COMPRESS
*errorMsg = QLatin1String("zlib support not compiled in");
@ -850,6 +860,7 @@ int RCCResourceLibrary::parseCompressionLevel(CompressionAlgorithm algo, const Q
if (ok) {
switch (algo) {
case CompressionAlgorithm::None:
case CompressionAlgorithm::Best:
return 0;
case CompressionAlgorithm::Zlib:
if (c >= 1 && c <= 9)

View File

@ -84,6 +84,7 @@ public:
Zlib,
Zstd,
Best = 99,
None = -1
};