]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
slightly improved ratio at -22
authorYann Collet <cyan@fb.com>
Sun, 19 Nov 2017 21:39:12 +0000 (13:39 -0800)
committerYann Collet <cyan@fb.com>
Sun, 19 Nov 2017 22:00:55 +0000 (14:00 -0800)
merging of repcode search into btsearch introduced a small compression ratio regressio at max level :
1.3.2 : 52728769
after repMerge patch : 52760789 (+32020)

A few minor changes have produced this difference.
They can be hard to spot.

This patch buys back about half of the difference,
by no longer inserting position at hc3 when a long match is found there.
It feels strangely counter-intuitive, but works :
after this patch : 52742555 (-18234)

lib/compress/zstd_lazy.c
lib/compress/zstd_opt.c
tests/paramgrill.c

index cd3d1530aacdee18d35a8b58cd25b6a4be09164d..a2c658bd3b3aa83f0555aca653b0a227b94ace9e 100644 (file)
@@ -16,8 +16,8 @@
 *  Binary Tree search
 ***************************************/
 /** ZSTD_insertBt1() : add one or multiple positions to tree.
-  ip : assumed <= iend-8 .
-*   @return : nb of positions added */
+ *  ip : assumed <= iend-8 .
+ * @return : nb of positions added */
 static U32 ZSTD_insertBt1(ZSTD_CCtx* zc,
                 const BYTE* const ip, const BYTE* const iend,
                 U32 nbCompares, U32 const mls, U32 const extDict)
@@ -42,7 +42,7 @@ static U32 ZSTD_insertBt1(ZSTD_CCtx* zc,
     U32* largerPtr  = smallerPtr + 1;
     U32 dummy32;   /* to be nullified at the end */
     U32 const windowLow = zc->lowLimit;
-    U32 matchEndIdx = current+8;
+    U32 matchEndIdx = current+8+1;
     size_t bestLength = 8;
 #ifdef ZSTD_C_PREDICT
     U32 predictedSmall = *(bt + 2*((current-1)&btMask) + 0);
@@ -122,8 +122,8 @@ static U32 ZSTD_insertBt1(ZSTD_CCtx* zc,
 
     *smallerPtr = *largerPtr = 0;
     if (bestLength > 384) return MIN(192, (U32)(bestLength - 384));   /* speed optimization */
-    if (matchEndIdx > current + 8) return matchEndIdx - (current + 8);
-    return 1;
+    assert(matchEndIdx > current + 8);
+    return matchEndIdx - (current + 8);
 }
 
 FORCE_INLINE_TEMPLATE
@@ -182,7 +182,7 @@ static size_t ZSTD_insertBtAndFindBestMatch (
     const U32 windowLow = zc->lowLimit;
     U32* smallerPtr = bt + 2*(current&btMask);
     U32* largerPtr  = bt + 2*(current&btMask) + 1;
-    U32 matchEndIdx = current+8;
+    U32 matchEndIdx = current+8+1;
     U32 dummy32;   /* to be nullified at the end */
     size_t bestLength = 0;
 
@@ -233,7 +233,8 @@ static size_t ZSTD_insertBtAndFindBestMatch (
 
     *smallerPtr = *largerPtr = 0;
 
-    zc->nextToUpdate = (matchEndIdx > current + 8) ? matchEndIdx - 8 : current+1;   /* skip repetitive patterns */
+    assert(matchEndIdx > current+8);
+    zc->nextToUpdate = matchEndIdx - 8;   /* skip repetitive patterns */
     return bestLength;
 }
 
index 7fd866f0a6a4f8a8337ea6db8984b9cd05db6007..7508aa1bc0bbf15054ed5e305dc329ed466864ba 100644 (file)
@@ -263,7 +263,7 @@ U32 ZSTD_insertBtAndGetAllMatches (
     U32 const windowLow = zc->lowLimit;
     U32* smallerPtr = bt + 2*(current&btMask);
     U32* largerPtr  = bt + 2*(current&btMask) + 1;
-    U32 matchEndIdx = current+8;   /* farthest referenced position of any match => detects repetitive patterns */
+    U32 matchEndIdx = current+8+1;   /* farthest referenced position of any match => detects repetitive patterns */
     U32 dummy32;   /* to be nullified at the end */
     U32 mnum = 0;
 
@@ -328,8 +328,9 @@ U32 ZSTD_insertBtAndGetAllMatches (
                 matches[0].off = (current - matchIndex3) + ZSTD_REP_MOVE;
                 matches[0].len = (U32)mlen;
                 mnum = 1;
-                if ( (mlen > sufficient_len)
-                   | (ip+mlen == iLimit) ) {  /* best possible */
+                if ( (mlen > sufficient_len) |
+                     (ip+mlen == iLimit) ) {  /* best possible length */
+                    zc->nextToUpdate = current+1;  /* skip insertion */
                     return 1;
     }   }   }   }
 
@@ -387,7 +388,8 @@ U32 ZSTD_insertBtAndGetAllMatches (
 
     *smallerPtr = *largerPtr = 0;
 
-    zc->nextToUpdate = (matchEndIdx > current + 8) ? matchEndIdx - 8 : current+1;  /* skip repetitive patterns */
+    assert(matchEndIdx > current+8);
+    zc->nextToUpdate = matchEndIdx - 8;  /* skip repetitive patterns */
     return mnum;
 }
 
index 5560e82f64d2a08209ea220cc66b1be9344a725a..081a284e42fb46a58d3516b838e15648c4c02e22 100644 (file)
@@ -310,8 +310,8 @@ static size_t BMK_benchParam(BMK_result_t* resultPtr,
 }
 
 
-const char* g_stratName[ZSTD_btultra] = {
-                "ZSTD_fast    ", "ZSTD_dfast   ",
+const char* g_stratName[ZSTD_btultra+1] = {
+                "(none)       ", "ZSTD_fast    ", "ZSTD_dfast   ",
                 "ZSTD_greedy  ", "ZSTD_lazy    ", "ZSTD_lazy2   ",
                 "ZSTD_btlazy2 ", "ZSTD_btopt   ", "ZSTD_btultra "};